History

Improve documentation

Nicolas Ettlin committed 4 years ago

Commit 16ccff51 parent 4d024101 file · +45 −29Browse files

Unified · Split

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