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
2 @extend %simple;2 @extend %simple;
3 3
4 .deprecated { @extend %label-red; }4 .deprecated { @extend %label-red; }
5
6 .attributes dl,
7 .attributes pre {
8 margin: 0;
9 }
5 10
6 .related-types {11 .related-types {
7 @extend %pre;12 @extend %pre;
8 margin-top: 0;13 margin: 0;
9 white-space: normal;14 white-space: normal;
10 }15 }
11 16
lib/docs/filters/scala/clean_html_v3.rb+30−3
@@ -102,7 +102,6 @@ module Docs · 101 unmodified lines
102 end102 end
103 103
104 attributes = at_css('.attributes')104 attributes = at_css('.attributes')
105 attributes.add_previous_sibling('<h3>Metadata</h3>')
106 105
107 tabs_names = css('.tabs.single .names .tab')106 tabs_names = css('.tabs.single .names .tab')
108 tabs_contents = css('.tabs.single .contents .tab')107 tabs_contents = css('.tabs.single .contents .tab')
@@ -112,7 +111,11 @@ module Docs · 3 unmodified lines
112 attributes.add_child("<dt>#{name.content}</dt>")111 attributes.add_child("<dt>#{name.content}</dt>")
113 attributes.add_child("<dd>#{contents.inner_html.strip}</dd>")112 attributes.add_child("<dd>#{contents.inner_html.strip}</dd>")
114 end113 end
115 at_css('.tabs').remove114
115 convert_dl_to_table(attributes)
116
117 tabs = at_css('.tabs')
118 tabs.remove unless tabs.nil? || tabs.parent['class'] == 'membersList'
116 end119 end
117 120
118 def format_members121 def format_members
@@ -138,7 +141,7 @@ module Docs · 19 unmodified lines
138 141
139 id = element['id']142 id = element['id']
140 element.remove_attribute('id')143 element.remove_attribute('id')
141 header['id'] = id144 header['id'] = id unless id.nil?
142 145
143 annotations = element.at_css('.annotations')146 annotations = element.at_css('.annotations')
144 annotations.name = 'small'147 annotations.name = 'small'
@@ -158,6 +161,10 @@ module Docs · 13 unmodified lines
158 dd.remove161 dd.remove
159 end162 end
160 163
164 # Format attributes as a table
165 dl = element.at_css('.attributes')
166 convert_dl_to_table(dl) unless dl.nil?
167
161 # Remove the unnecessary wrapper element168 # Remove the unnecessary wrapper element
162 element.replace(element.inner_html)169 element.replace(element.inner_html)
163 end170 end
@@ -176,6 +183,26 @@ module Docs · 12 unmodified lines
176 end183 end
177 end184 end
178 185
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
179 end206 end
180 end207 end
181end208end
lib/docs/scrapers/scala.rb+8−1
@@ -26,7 +26,14 @@ module Docs · 25 unmodified lines
26 self.release = '3.1.1'26 self.release = '3.1.1'
27 self.base_url = 'https://scala-lang.org/api/3.1.1/'27 self.base_url = 'https://scala-lang.org/api/3.1.1/'
28 self.root_path = 'index.html'28 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 ]
30 37
31 html_filters.push 'scala/entries_v3', 'scala/clean_html_v3'38 html_filters.push 'scala/entries_v3', 'scala/clean_html_v3'
32 end39 end