Module: YARD::Templates::Helpers::HtmlHelper
- Defined in:
- lib/yard-api/templates/helpers/html_helper.rb
Instance Method Summary collapse
-
#anchor_for_with_api(object) ⇒ Object
(also: #anchor_for)
Because we want the endpoints’ URLs (an anchor part) to show up as “-endpoint” as opposed to “-instance_method”.
-
#htmlify(text, markup = options.markup) ⇒ String
Turns text into HTML using
markupstyle formatting. - #htmlify_tag_type(tag) ⇒ Object
-
#link_appendix(ref) ⇒ Object
override yard-appendix link_appendix.
- #logger ⇒ Object
- #sidebar_link(href, title, is_active) ⇒ Object
- #static_pages ⇒ Object
- #topicize(str) ⇒ Object
- #url_for_file(file, anchor = nil) ⇒ Object
- #visible_static_pages ⇒ Object
Instance Method Details
#anchor_for_with_api(object) ⇒ Object Also known as: anchor_for
Because we want the endpoints’ URLs (an anchor part) to show up as “-endpoint” as opposed to “-instance_method”
151 152 153 154 155 156 157 158 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 151 def anchor_for_with_api(object) case object when YARD::CodeObjects::MethodObject "#{object.name}-endpoint" else anchor_for_without_api(object) end end |
#htmlify(text, markup = options.markup) ⇒ String
Turns text into HTML using markup style formatting.
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 115 def htmlify(text, markup = .markup) markup_meth = "html_markup_#{markup}" return text unless respond_to?(markup_meth) return "" unless text return text unless markup html = send(markup_meth, text) if html.respond_to?(:encode) html = html.force_encoding(text.encoding) # for libs that mess with encoding html = html.encode(:invalid => :replace, :replace => '?') end html = resolve_links(html) html end |
#htmlify_tag_type(tag) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 129 def htmlify_tag_type(tag) co = if tag.type =~ /API::(?:(\S+)::)?(\S+)\b/ # discard [] at the end denoting array of objects P(tag.type.gsub(/\[\]$/, '')) end if co && !co.is_a?(YARD::CodeObjects::Proxy) begin linkify(co, tag.type.split(YARD::CodeObjects::NSEP)[1..-1].join(YARD::CodeObjects::NSEP)) rescue Exception => e YARD::APIPlugin.logger.warn e "" end else tag.type end end |
#link_appendix(ref) ⇒ Object
override yard-appendix link_appendix
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 81 def link_appendix(ref) logger.debug "Linking appendix: #{ref}" unless appendix = lookup_appendix(ref.to_s) YARD::APIPlugin.on_error "Unable to locate referenced appendix '#{ref}'" return ref end html_file = if [:all_resources] && .one_file 'index.html' elsif [:all_resources] 'all_resources.html' else url_for(appendix.namespace) end bookmark = "#{appendix.name.to_s.gsub(' ', '+')}-appendix" link_url("#{html_file}##{bookmark}", appendix.title).tap do |link| logger.debug "\tAppendix link: #{link}" end end |
#logger ⇒ Object
162 163 164 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 162 def logger YARD::APIPlugin.logger end |
#sidebar_link(href, title, is_active) ⇒ Object
103 104 105 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 103 def (href, title, is_active) link_url(href, title, { class: is_active ? 'active' : '' }) end |
#static_pages ⇒ Object
20 21 22 23 24 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 20 def static_pages() @@static_pages ||= begin locate_static_pages(YARD::APIPlugin.) end end |
#topicize(str) ⇒ Object
4 5 6 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 4 def topicize(str) ::YARD::APIPlugin::Serializer.topicize(str) end |
#url_for_file(file, anchor = nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 8 def url_for_file(file, anchor = nil) link = file.filename link += (anchor ? '#' + urlencode(anchor) : '') link end |
#visible_static_pages ⇒ Object
14 15 16 17 18 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 14 def visible_static_pages() @@visible_static_pages ||= begin static_pages.reject { |page| page[:exclude_from_sidebar] } end end |