History

Format attributes as a table

Nicolas Ettlin committed 4 years ago

Commit 55ec2b61 parent afe3a263 files · +44 −5Browse files

Unified · Split

3 files
  1. assets/stylesheets/pages/_scala.scss +6 −1
  2. lib/docs/filters/scala/clean_html_v3.rb +30 −3
  3. lib/docs/scrapers/scala.rb +8 −1
assets/stylesheets/pages/_scala.scss+6−1
@@ -2,10 +2,15 @@ · 1 unmodified line
22 @extend %simple;
33
44 .deprecated { @extend %label-red; }
5+
6+ .attributes dl,
7+ .attributes pre {
8+ margin: 0;
9+ }
510
611 .related-types {
712 @extend %pre;
8− margin-top: 0;
13+ margin: 0;
914 white-space: normal;
1015 }
1116
lib/docs/filters/scala/clean_html_v3.rb+30−3
@@ -102,7 +102,6 @@ module Docs · 101 unmodified lines
102102 end
103103
104104 attributes = at_css('.attributes')
105− attributes.add_previous_sibling('<h3>Metadata</h3>')
106105
107106 tabs_names = css('.tabs.single .names .tab')
108107 tabs_contents = css('.tabs.single .contents .tab')
@@ -112,7 +111,11 @@ module Docs · 3 unmodified lines
112111 attributes.add_child("<dt>#{name.content}</dt>")
113112 attributes.add_child("<dd>#{contents.inner_html.strip}</dd>")
114113 end
115− at_css('.tabs').remove
114+
115+ convert_dl_to_table(attributes)
116+
117+ tabs = at_css('.tabs')
118+ tabs.remove unless tabs.nil? || tabs.parent['class'] == 'membersList'
116119 end
117120
118121 def format_members
@@ -138,7 +141,7 @@ module Docs · 19 unmodified lines
138141
139142 id = element['id']
140143 element.remove_attribute('id')
141− header['id'] = id
144+ header['id'] = id unless id.nil?
142145
143146 annotations = element.at_css('.annotations')
144147 annotations.name = 'small'
@@ -158,6 +161,10 @@ module Docs · 13 unmodified lines
158161 dd.remove
159162 end
160163
164+ # Format attributes as a table
165+ dl = element.at_css('.attributes')
166+ convert_dl_to_table(dl) unless dl.nil?
167+
161168 # Remove the unnecessary wrapper element
162169 element.replace(element.inner_html)
163170 end
@@ -176,6 +183,26 @@ module Docs · 12 unmodified lines
176183 end
177184 end
178185
186+ def convert_dl_to_table(dl)
187+ table = Nokogiri::XML::Node.new('table', doc)
188+ table['class'] = 'attributes'
189+
190+ dl.css('> dt').each do |dt|
191+ dd = dt.next_element
192+ has_dd = dd.name == 'dd' rescue false
193+
194+ tr = Nokogiri::XML::Node.new('tr', doc)
195+ colspan = has_dd ? '' : ' colspan="2"' # handle <dt> without following <dt>
196+ tr.add_child("<th#{colspan}>#{dt.inner_html.sub(/:$/, '')}</th>")
197+
198+ tr.add_child("<td>#{dd.inner_html}</td>") if has_dd
199+
200+ table.add_child(tr)
201+ end
202+
203+ dl.replace(table)
204+ end
205+
179206 end
180207 end
181208 end
lib/docs/scrapers/scala.rb+8−1
@@ -26,7 +26,14 @@ module Docs · 25 unmodified lines
2626 self.release = '3.1.1'
2727 self.base_url = 'https://scala-lang.org/api/3.1.1/'
2828 self.root_path = 'index.html'
29− # options[:container] = '#main-content'
29+
30+ options[:skip_patterns] = [
31+ # Ignore class names with include “#”, which cause issues with the scraper
32+ /%23/,
33+
34+ # Ignore local links to the Java documentation created by a Scaladoc bug
35+ /java\/lang/,
36+ ]
3037
3138 html_filters.push 'scala/entries_v3', 'scala/clean_html_v3'
3239 end