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

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

Instance Method Summary collapse

Instance Method Details

#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



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

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

override yard-appendix link_appendix



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 74

def link_appendix(ref)
  puts "Linking appendix: #{ref}" if api_options.verbose

  unless appendix = lookup_appendix(ref.to_s)
    raise "Unable to locate referenced appendix '#{ref}'"
  end

  html_file = if options[:all_resources] && api_options.one_file
    'index.html'
  elsif options[:all_resources]
    'all_resources.html'
  else
    topic, controller = *lookup_topic(appendix.namespace.to_s)

    unless topic
      raise "Unable to locate topic for appendix: #{ref}"
    end

    "#{topicize(topic.first)}.html"
  end

  bookmark = "#{appendix.name.to_s.gsub(' ', '+')}-appendix"
  link_url("#{html_file}##{bookmark}", appendix.title).tap do |link|
    puts "\tAppendix link: #{link}" if api_options.verbose
  end
end

TODO: this has to work with the All Resources page.



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 102

def sidebar_link(title, href, options={})
  options[:class_name] ||= begin
    if object.is_a?(String) && "#{url_for(topicize(object))}.html" == href
      options[:class_name] = 'active'
    end
  end

  options[:class_name] ||= (object == href ? 'active' : nil)

  "    <a href=\"\#{url_for(href)}\" class=\"\#{options[:class_name]}\">\#{title}</a>\n  HTML\nend\n"

#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)
  str.split("\n")[0].gsub(' ', '_').underscore
end

#url_for_file(filename, anchor = nil) ⇒ Object



8
9
10
11
12
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 8

def url_for_file(filename, anchor = nil)
  link = filename.filename
  link += (anchor ? '#' + urlencode(anchor) : '')
  link
end