Module: PDoc::Generators::Html::Helpers::LinkHelper
Instance Method Summary collapse
- #auto_link(obj, options = {}) ⇒ Object
- #auto_link_code(obj, options = {}) ⇒ Object
- #auto_link_content(content) ⇒ Object
- #auto_link_types(types, options = {}) ⇒ Object
- #dom_id(obj) ⇒ Object
- #path_prefix ⇒ Object
- #path_to(obj) ⇒ Object
Instance Method Details
#auto_link(obj, options = {}) ⇒ Object
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, = {}) if obj.is_a?(String) original = obj obj = root.find(obj) return original unless obj end name = .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()) end |
#auto_link_code(obj, options = {}) ⇒ Object
92 93 94 |
# File 'lib/pdoc/generators/html/helpers.rb', line 92 def auto_link_code(obj, = {}) "<code>#{auto_link(obj, )}</code>" end |
#auto_link_content(content) ⇒ Object
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 |
#auto_link_types(types, options = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/pdoc/generators/html/helpers.rb', line 111 def auto_link_types(types, = {}) 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], )}…]" else auto_link(t, ) 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_prefix ⇒ Object
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 |