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
- #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.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 117 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
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 100 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 75 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
102 103 104 105 106 107 108 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 102 def (title, href, ={}) [: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 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 14 def static_pages() return @static_pages if @static_pages = YARD::APIPlugin. paths = Array(.static).map do |entry| pages = if entry.is_a?(Hash) glob = entry['glob'] blacklist = Array(entry['exclude']) unless glob raise "Invalid static page entry, expected Hash to contain a 'glob' parameter: #{entry}" end pages = Dir.glob(entry['glob']) if blacklist.any? pages.delete_if { |p| blacklist.any? { |filter| p.match(filter) } } end pages elsif entry.is_a?(Array) entry.map(&:to_s) elsif entry.is_a?(String) [ entry ] end end.flatten.compact.uniq.map { |path| File.join(.source, path) } markdown_exts = YARD::Templates::Helpers::MarkupHelper::MARKUP_EXTENSIONS[:markdown] readme_page = .readme pages = Dir.glob(paths) if readme_page.present? && !.one_file pages.delete_if { |page| page.match(readme_page) } end @static_pages = pages.map do |page| filename = 'file.' + File.split(page).last.sub(/\..*$/, '.html') # extract page title if it's a markdown document; title is expected to # be an h1 on the very first line: title = if markdown_exts.include?(File.extname(page).sub('.', '')) (File.open(page, &:gets) || '').strip.sub('# ', '') else # otherwise we'll just sanitize the file name File.basename(page).sub(/\.\w+$/, '').gsub(/\W/, ' ').gsub(/\s+/, ' ').capitalize end if .verbose puts "Serializing static page #{page}" end { src: page, filename: filename, title: title } end end |
#topicize(str) ⇒ Object
4 5 6 |
# File 'lib/yard-api/templates/helpers/html_helper.rb', line 4 def topicize(str) str.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 |