Class: Web::Wiki::Linker

Inherits:
Object show all
Defined in:
lib/web/wiki/linker.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeLinker

Returns a new instance of Linker.



4
5
# File 'lib/web/wiki/linker.rb', line 4

def initialize
end

Instance Method Details

#html_regexpObject



7
8
9
# File 'lib/web/wiki/linker.rb', line 7

def html_regexp
  /((<textarea)(.)*(\/textarea>))|(<a[ ]*href=[\"']*([^\"'>]*)[\"']*>([^(<\/)]*)<\/a>)|(<[^>]*>)/mi #"'
end


24
25
26
27
28
29
30
# File 'lib/web/wiki/linker.rb', line 24

def make_link( pagename )
  if (Web::Wiki::pref( :script_url ) && Web::Wiki::pref( :store_url ) )
    "<a href=\"#{Web::Wiki::pref(:script_url)}/#{pagename}.html\">#{pagename}</a>"
  else
    "<a href=\"?page.name=#{Web::escape(pagename)}\">#{pagename}</a>"
  end
end


63
64
65
66
67
68
69
# File 'lib/web/wiki/linker.rb', line 63

def replace_links(string )
  out = StringIO.new
  scanner = StringScanner.new(string)
  while scan_linked_word( scanner , out ) || scan_bumpy_word( scanner , out ) || scan_html( scanner , out ) || scan_other( scanner , out )
  end
  out.string
end

#scan_bumpy_word(scanner, output) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/web/wiki/linker.rb', line 32

def scan_bumpy_word( scanner , output )
  if scanner.scan(/([A-Z][\w\/]*[a-z][\w\/]*[A-Z]\w*)/)
    if Web::Wiki.page_list.include?(scanner[1])
      output.print make_link( scanner[1] )
    else
      output.print "#{scanner[1]}<a href=\"?page.name=#{Web::escape(scanner[1])}&action=edit\">?</a>"
    end
    true
  else
    false
  end
end

#scan_html(scanner, output) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/web/wiki/linker.rb', line 45

def scan_html( scanner , output )
  if scanner.scan(html_regexp)
    output.print scanner[0]
    true
  else
    false
  end
end

#scan_linked_word(scanner, output) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/web/wiki/linker.rb', line 11

def scan_linked_word( scanner , output )
  if scanner.scan(/\[\[(.*?)\]\]/)
    if Web::Wiki.page_list.include?(scanner[1])
      output.print "<a href=\"?page.name=#{Web::escape(scanner[1])}\">#{scanner[1]}</a>"
    else
      output.print "#{scanner[1]}<a href=\"?page.name=#{Web::escape(scanner[1])}&action=edit\">?</a>"
    end
    true
  else
    false
  end
end

#scan_other(scanner, output) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/web/wiki/linker.rb', line 54

def scan_other( scanner , output )
  if scanner.scan(/(\w+|\s+|.)/)
    output.print scanner[1]
    true
  else
    false
  end
end