Unified · Split
| @@ -8,6 +8,7 @@ module Docs · 7 unmodified lines | ||
| 8 | 8 | css('.documentableFilter, .documentableAnchor, .documentableBrief').remove |
| 9 | 9 | |
| 10 | 10 | format_title |
| 11 | + format_signature | |
| 11 | 12 | format_top_links |
| 12 | 13 | format_metadata |
| 13 | 14 | format_members |
| @@ -16,41 +17,49 @@ module Docs · 2 unmodified lines | ||
| 16 | 17 | doc |
| 17 | 18 | end |
| 18 | 19 | |
| 20 | + private | |
| 21 | + | |
| 22 | + # Formats the title of the page | |
| 19 | 23 | def format_title |
| 20 | − # Add the kind of page to the title | |
| 21 | 24 | cover_header = at_css('.cover-header') |
| 22 | − unless cover_header.nil? | |
| 23 | − icon = cover_header.at_css('.micon') | |
| 24 | − types = { | |
| 25 | − cl: 'Class', | |
| 26 | − ob: 'Object', | |
| 27 | − tr: 'Trait', | |
| 28 | − en: 'Enum', | |
| 29 | − ty: 'Type', | |
| 30 | − pa: 'Package', | |
| 31 | − } | |
| 32 | − type_id = cover_header.at_css('.micon')['class'] | |
| 33 | − type_id.remove!('micon ') | |
| 34 | − type_id.remove!('-wc') | |
| 35 | − type = types[type_id.to_sym] | |
| 36 | − name = CGI.escapeHTML cover_header.at_css('h1').text | |
| 37 | − | |
| 38 | − package = at_css('.breadcrumbs a:nth-of-type(3)').text | |
| 39 | − package = package + '.' unless name.empty? || package.empty? | |
| 40 | − | |
| 41 | − title = root_page? ? 'Package root' : "#{type} #{package}#{name}".strip | |
| 42 | − cover_header.replace "<h1>#{title}</h1>" | |
| 43 | − end | |
| 25 | + return if cover_header.nil? | |
| 26 | + | |
| 27 | + # Add the kind of page to the title | |
| 28 | + icon = cover_header.at_css('.micon') | |
| 29 | + types = { | |
| 30 | + cl: 'Class', | |
| 31 | + ob: 'Object', | |
| 32 | + tr: 'Trait', | |
| 33 | + en: 'Enum', | |
| 34 | + ty: 'Type', | |
| 35 | + pa: 'Package', | |
| 36 | + } | |
| 37 | + type_id = cover_header.at_css('.micon')['class'] | |
| 38 | + type_id.remove!('micon ') | |
| 39 | + type_id.remove!('-wc') | |
| 40 | + type = types[type_id.to_sym] | |
| 41 | + name = CGI.escapeHTML cover_header.at_css('h1').text | |
| 42 | + | |
| 43 | + # Add the package name | |
| 44 | + package = at_css('.breadcrumbs a:nth-of-type(3)').text | |
| 45 | + package = package + '.' unless name.empty? || package.empty? | |
| 46 | + | |
| 47 | + # Replace the title | |
| 48 | + title = root_page? ? 'Package root' : "#{type} #{package}#{name}".strip | |
| 49 | + cover_header.replace "<h1>#{title}</h1>" | |
| 50 | + end | |
| 44 | 51 | |
| 45 | − # Signature | |
| 52 | + # Formats the signature block at the top of the page | |
| 53 | + def format_signature | |
| 46 | 54 | signature = at_css('.signature') |
| 47 | 55 | signature_annotations = signature.at_css('.annotations') |
| 48 | 56 | signature_annotations.name = 'small' unless signature_annotations.nil? |
| 49 | 57 | signature.replace "<h2 id=\"signature\">#{signature.inner_html}</h2>" |
| 50 | 58 | end |
| 51 | 59 | |
| 60 | + # Formats the top links (companion page, source code) | |
| 52 | 61 | def format_top_links |
| 53 | − # Companion page | |
| 62 | + # Companion page (e.g. List ↔ List$) | |
| 54 | 63 | links = [] |
| 55 | 64 | at_css('.attributes').css('dt').each do |dt| |
| 56 | 65 | next if dt.content.strip != 'Companion:' |
| @@ -82,8 +91,9 @@ module Docs · 25 unmodified lines | ||
| 82 | 91 | title.add_next_sibling("<div class=\"links\">#{links.join(' • ')}</div>") |
| 83 | 92 | end |
| 84 | 93 | |
| 94 | + # Metadata about the whole file (e.g. supertypes) | |
| 85 | 95 | def format_metadata |
| 86 | − # Metadata (attributes) | |
| 96 | + # Format the values | |
| 87 | 97 | css('.tabs.single .monospace').each do |node| |
| 88 | 98 | node.css('> div').each do |div| |
| 89 | 99 | div['class'] = 'member' |
| @@ -91,7 +101,7 @@ module Docs · 1 unmodified line | ||
| 91 | 101 | |
| 92 | 102 | node['class'] = 'related-types' |
| 93 | 103 | |
| 94 | − if node.children.count > 15 | |
| 104 | + if node.children.count > 15 # Hide too large lists | |
| 95 | 105 | node.replace "<details> |
| 96 | 106 | <summary>#{node.children.count} types</summary> |
| 97 | 107 | #{node.to_html} |
| @@ -101,6 +111,7 @@ module Docs · 3 unmodified lines | ||
| 101 | 111 | |
| 102 | 112 | attributes = at_css('.attributes') |
| 103 | 113 | |
| 114 | + # Change the HTML structure | |
| 104 | 115 | tabs_names = css('.tabs.single .names .tab') |
| 105 | 116 | tabs_contents = css('.tabs.single .contents .tab') |
| 106 | 117 | tabs_names.zip(tabs_contents).each do |name, contents| |
| @@ -116,8 +127,9 @@ module Docs · 9 unmodified lines | ||
| 116 | 127 | tabs.remove unless tabs.nil? || tabs.parent['class'] == 'membersList' |
| 117 | 128 | end |
| 118 | 129 | |
| 130 | + # Format the members (methods, values…) | |
| 119 | 131 | def format_members |
| 120 | − # Headings | |
| 132 | + # Section headings | |
| 121 | 133 | css('.cover h2').each do |node| |
| 122 | 134 | node.name = 'h3' |
| 123 | 135 | end |
| @@ -126,13 +138,14 @@ module Docs · 2 unmodified lines | ||
| 126 | 138 | '.membersList h3', |
| 127 | 139 | |
| 128 | 140 | # Custom group headers for which Scaladoc generates invalid HTML |
| 141 | + # (<h3><p>…</p></h3>) | |
| 129 | 142 | '.documentableList > h3:empty + p' |
| 130 | 143 | ).each do |node| |
| 131 | 144 | node.name = 'h2' |
| 132 | 145 | node.content = node.content |
| 133 | 146 | end |
| 134 | 147 | |
| 135 | − # Methods | |
| 148 | + # Individual members | |
| 136 | 149 | css('.documentableElement').each do |element| |
| 137 | 150 | header = element.at_css('.header') |
| 138 | 151 | header.name = 'h3' |
| @@ -181,9 +194,12 @@ module Docs · 42 unmodified lines | ||
| 181 | 194 | end |
| 182 | 195 | end |
| 183 | 196 | |
| 197 | + # Simplify the HTML structure by removing useless elements | |
| 184 | 198 | def simplify_html |
| 199 | + # Remove unneeded parts of the document | |
| 185 | 200 | @doc = at_css('#content > div') |
| 186 | 201 | |
| 202 | + # Remove the useless elements around members | |
| 187 | 203 | css('.documentableList > *').each do |element| |
| 188 | 204 | element.parent = doc |
| 189 | 205 | end |