Class: Wikilink::Converter::Namespace::Default

Inherits:
Wikilink::Converter::Namespace show all
Defined in:
lib/wikilink/converter/namespace.rb

Constant Summary

Constants inherited from Wikilink::Converter::Namespace

DEFAULT_NAME

Instance Attribute Summary

Attributes inherited from Wikilink::Converter::Namespace

#options

Instance Method Summary collapse

Methods inherited from Wikilink::Converter::Namespace

#config, #initialize

Methods included from HTMLAttributes

#html_class

Methods included from LinkHelper

#link_to

Constructor Details

This class inherits a constructor from Wikilink::Converter::Namespace

Instance Method Details

#run(run_options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wikilink/converter/namespace.rb', line 30

def run(run_options)
  return super if @block

  path = run_options[:path].to_s
  path, fragment = path.split('#', 2)
  path, query = path.split('?', 2)

  fragment = '#' + fragment if fragment
  query = '?' + query if query

  url = to_url(path, fragment, query)

  link_to(run_options[:name], url, :class => html_class(run_options[:class]))
end

#to_url(path, fragment, query) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/wikilink/converter/namespace.rb', line 45

def to_url(path, fragment, query)
  if path.nil? || path.empty?
    [query, fragment].join
  else
    [options[:prefix], path, options[:suffix], query, fragment].join
  end
end