Module: PDoc::Generators::Html::Helpers::LinkHelper

Included in:
DocPage, Page, Website
Defined in:
lib/pdoc/generators/html/helpers.rb

Instance Method Summary collapse

Instance Method Details



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/pdoc/generators/html/helpers.rb', line 77

def auto_link(obj, options = {})
  if obj.is_a?(String)
    original = obj
    obj = root.find(obj)
    return original unless obj
  end
  name = options.delete(:name) == :short ? obj.name : obj.full_name
  if obj.type == 'section'
    title = obj.full_name
  else
    title = "#{obj.full_name} (#{obj.type})"
  end
  link_to(name, path_to(obj), { :title => title }.merge(options))
end


92
93
94
# File 'lib/pdoc/generators/html/helpers.rb', line 92

def auto_link_code(obj, options = {})
  "<code>#{auto_link(obj, options)}</code>"
end


96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pdoc/generators/html/helpers.rb', line 96

def auto_link_content(content)
  return '' if content.nil?
  content.gsub!(/\[\[([a-zA-Z]+)\s+section\]\]/) do |m|
    result = auto_link(root.find($1), :name => :long)
    result
  end
  content.gsub(/\[\[([a-zA-Z$\.#]+)(?:\s+([^\]]+))?\]\]/) do |m|
    if doc_instance = root.find($1)
      $2 ? link_to($2, path_to(doc_instance)) : auto_link_code(doc_instance, :name => :long)
    else
      $1
    end
  end
end


111
112
113
114
115
116
117
118
119
120
# File 'lib/pdoc/generators/html/helpers.rb', line 111

def auto_link_types(types, options = {})
  types = types.split(/\s+\|\s+/) if types.is_a?(String)
  types.map do |t|
    if match = /^\[([\w\d\$\.\(\)#]*[\w\d\$\(\)#])...\s*\]$/.match(t) # e.g.: [Element...]
      "[#{auto_link(match[1], options)}…]"
    else
      auto_link(t, options)
    end
  end
end

#dom_id(obj) ⇒ Object



122
123
124
# File 'lib/pdoc/generators/html/helpers.rb', line 122

def dom_id(obj)
  "#{obj.id}-#{obj.type.gsub(/\s+/, '_')}"
end

#path_prefixObject



68
69
70
# File 'lib/pdoc/generators/html/helpers.rb', line 68

def path_prefix
  "../" * depth
end

#path_to(obj) ⇒ Object



72
73
74
75
# File 'lib/pdoc/generators/html/helpers.rb', line 72

def path_to(obj)
  path = path_prefix << obj.url << '/'
  Website.pretty_urls? ? path : "#{path}index.html"
end