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
88 css('.documentableFilter, .documentableAnchor, .documentableBrief').remove
99
1010 format_title
11+ format_signature
1112 format_top_links
1213 format_metadata
1314 format_members
@@ -16,41 +17,49 @@ module Docs · 2 unmodified lines
1617 doc
1718 end
1819
20+ private
21+
22+ # Formats the title of the page
1923 def format_title
20− # Add the kind of page to the title
2124 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
4451
45− # Signature
52+ # Formats the signature block at the top of the page
53+ def format_signature
4654 signature = at_css('.signature')
4755 signature_annotations = signature.at_css('.annotations')
4856 signature_annotations.name = 'small' unless signature_annotations.nil?
4957 signature.replace "<h2 id=\"signature\">#{signature.inner_html}</h2>"
5058 end
5159
60+ # Formats the top links (companion page, source code)
5261 def format_top_links
53− # Companion page
62+ # Companion page (e.g. List ↔ List$)
5463 links = []
5564 at_css('.attributes').css('dt').each do |dt|
5665 next if dt.content.strip != 'Companion:'
@@ -82,8 +91,9 @@ module Docs · 25 unmodified lines
8291 title.add_next_sibling("<div class=\"links\">#{links.join(' • ')}</div>")
8392 end
8493
94+ # Metadata about the whole file (e.g. supertypes)
8595 def format_metadata
86− # Metadata (attributes)
96+ # Format the values
8797 css('.tabs.single .monospace').each do |node|
8898 node.css('> div').each do |div|
8999 div['class'] = 'member'
@@ -91,7 +101,7 @@ module Docs · 1 unmodified line
91101
92102 node['class'] = 'related-types'
93103
94− if node.children.count > 15
104+ if node.children.count > 15 # Hide too large lists
95105 node.replace "<details>
96106 <summary>#{node.children.count} types</summary>
97107 #{node.to_html}
@@ -101,6 +111,7 @@ module Docs · 3 unmodified lines
101111
102112 attributes = at_css('.attributes')
103113
114+ # Change the HTML structure
104115 tabs_names = css('.tabs.single .names .tab')
105116 tabs_contents = css('.tabs.single .contents .tab')
106117 tabs_names.zip(tabs_contents).each do |name, contents|
@@ -116,8 +127,9 @@ module Docs · 9 unmodified lines
116127 tabs.remove unless tabs.nil? || tabs.parent['class'] == 'membersList'
117128 end
118129
130+ # Format the members (methods, values…)
119131 def format_members
120− # Headings
132+ # Section headings
121133 css('.cover h2').each do |node|
122134 node.name = 'h3'
123135 end
@@ -126,13 +138,14 @@ module Docs · 2 unmodified lines
126138 '.membersList h3',
127139
128140 # Custom group headers for which Scaladoc generates invalid HTML
141+ # (<h3><p>…</p></h3>)
129142 '.documentableList > h3:empty + p'
130143 ).each do |node|
131144 node.name = 'h2'
132145 node.content = node.content
133146 end
134147
135− # Methods
148+ # Individual members
136149 css('.documentableElement').each do |element|
137150 header = element.at_css('.header')
138151 header.name = 'h3'
@@ -181,9 +194,12 @@ module Docs · 42 unmodified lines
181194 end
182195 end
183196
197+ # Simplify the HTML structure by removing useless elements
184198 def simplify_html
199+ # Remove unneeded parts of the document
185200 @doc = at_css('#content > div')
186201
202+ # Remove the useless elements around members
187203 css('.documentableList > *').each do |element|
188204 element.parent = doc
189205 end