Module: YARD::Templates::Helpers::HtmlHelper

Defined in:
lib/yard-api/templates/helpers/html_helper.rb

Instance Method Summary collapse

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”



142
143
144
145
146
147
148
149
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 142

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.

Parameters:

  • text (String)

    the text to format

  • markup (Symbol) (defaults to: options.markup)

    examples are :markdown, :textile, :rdoc. To add a custom markup type, see MarkupHelper

Returns:

  • (String)

    the HTML



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 106

def htmlify(text, markup = options.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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 120

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

override yard-appendix link_appendix



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 72

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 options[:all_resources] && api_options.one_file
    'index.html'
  elsif options[: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

#loggerObject



153
154
155
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 153

def logger
  YARD::APIPlugin.logger
end


94
95
96
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 94

def sidebar_link(href, title, is_active)
  link_url(href, title, { class: is_active ? 'active' : '' })
end

#static_pagesObject



14
15
16
17
18
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 14

def static_pages()
  @@static_pages ||= begin
    locate_static_pages(YARD::APIPlugin.options)
  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