Module: YARD::Templates::Helpers::HtmlHelper
- Defined in:
- lib/yard-api/templates/helpers/html_helper.rb
Instance Method Summary collapse
-
#htmlify(text, markup = options.markup) ⇒ String
Turns text into HTML using
markupstyle formatting. -
#link_appendix(ref) ⇒ Object
override yard-appendix link_appendix.
-
#sidebar_link(title, href, options = {}) ⇒ Object
TODO: this has to work with the All Resources page.
- #static_pages ⇒ Object
- #topicize(str) ⇒ Object
- #url_for_file(filename, anchor = nil) ⇒ Object
Instance Method Details
#htmlify(text, markup = options.markup) ⇒ String
Turns text into HTML using markup style formatting.
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 = .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 |
#link_appendix(ref) ⇒ Object
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 .verbose unless appendix = lookup_appendix(ref.to_s) raise "Unable to locate referenced appendix '#{ref}'" end html_file = if [:all_resources] && .one_file 'index.html' elsif [: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 .verbose end end |
#sidebar_link(title, href, options = {}) ⇒ Object
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 (title, href, ={}) [:class_name] ||= begin if object.is_a?(String) && "#{url_for(topicize(object))}.html" == href [:class_name] = 'active' end end [:class_name] ||= (object == href ? 'active' : nil) " <a href=\"\#{url_for(href)}\" class=\"\#{options[:class_name]}\">\#{title}</a>\n HTML\nend\n" |
#static_pages ⇒ Object
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.) 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 |