Class: PseudoHiki::AutoLink::WikiName

Inherits:
Object
  • Object
show all
Defined in:
lib/pseudohiki/autolink.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ WikiName

Returns a new instance of WikiName.



22
23
24
25
# File 'lib/pseudohiki/autolink.rb', line 22

def initialize(options={})
  @options = WikiName.default_options.dup.merge!(options)
  @auto_linker = @options[:url] ? URL : Off
end

Class Method Details

.default_optionsObject



18
19
20
# File 'lib/pseudohiki/autolink.rb', line 18

def self.default_options
  @default_options
end

Instance Method Details

#add_tag(url) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/pseudohiki/autolink.rb', line 39

def add_tag(url)
  if escaped_wiki_name?(url)
    url[1..-1]
  elsif url.start_with?(ESCAPE_CHAR)
    "^[[#{url[1..-1]}]]"
  else
    "[[#{url}]]"
  end
end

Returns:

  • (Boolean)


27
28
29
# File 'lib/pseudohiki/autolink.rb', line 27

def auto_link_url?
  @options[:url]
end

#escaped_wiki_name?(wiki_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/pseudohiki/autolink.rb', line 31

def escaped_wiki_name?(wiki_name)
  @options[:escape_wiki_name] and wiki_name.start_with?(ESCAPE_CHAR)
end

Returns:

  • (Boolean)


35
36
37
# File 'lib/pseudohiki/autolink.rb', line 35

def in_link_tag?(preceding_str)
  URL.in_link_tag?(preceding_str)
end


54
55
56
57
# File 'lib/pseudohiki/autolink.rb', line 54

def link(line)
  line = @auto_linker.link(line)
  @options[:wiki_name] ? link_wiki_name(line) : line
end


49
50
51
52
# File 'lib/pseudohiki/autolink.rb', line 49

def link_wiki_name(line)
  return line if not WIKI_NAME_RE.match? line or VERBATIM_LEAF_HEAD_RE.match? line
  line.gsub(WIKI_NAME_RE) {|url| in_link_tag?($`) ? url : add_tag(url) }
end