[devdocsgjs/main: 202/239] Format attributes as a table
- From: Andy Holmes <andyholmes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devdocsgjs/main: 202/239] Format attributes as a table
- Date: Fri, 8 Apr 2022 07:47:43 +0000 (UTC)
commit 55ec2b6302eb2efee92de716c0fb98186afcba61
Author: Nicolas Ettlin <nicolas ettlin me com>
Date: Tue Feb 15 19:43:25 2022 +0100
Format attributes as a table
assets/stylesheets/pages/_scala.scss | 7 ++++++-
lib/docs/filters/scala/clean_html_v3.rb | 33 ++++++++++++++++++++++++++++++---
lib/docs/scrapers/scala.rb | 9 ++++++++-
3 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/assets/stylesheets/pages/_scala.scss b/assets/stylesheets/pages/_scala.scss
index 6ddb5dc0..94b8f7b4 100644
--- a/assets/stylesheets/pages/_scala.scss
+++ b/assets/stylesheets/pages/_scala.scss
@@ -2,10 +2,15 @@
@extend %simple;
.deprecated { @extend %label-red; }
+
+ .attributes dl,
+ .attributes pre {
+ margin: 0;
+ }
.related-types {
@extend %pre;
- margin-top: 0;
+ margin: 0;
white-space: normal;
}
diff --git a/lib/docs/filters/scala/clean_html_v3.rb b/lib/docs/filters/scala/clean_html_v3.rb
index f2d4c793..207d3ccd 100644
--- a/lib/docs/filters/scala/clean_html_v3.rb
+++ b/lib/docs/filters/scala/clean_html_v3.rb
@@ -102,7 +102,6 @@ module Docs
end
attributes = at_css('.attributes')
- attributes.add_previous_sibling('<h3>Metadata</h3>')
tabs_names = css('.tabs.single .names .tab')
tabs_contents = css('.tabs.single .contents .tab')
@@ -112,7 +111,11 @@ module Docs
attributes.add_child("<dt>#{name.content}</dt>")
attributes.add_child("<dd>#{contents.inner_html.strip}</dd>")
end
- at_css('.tabs').remove
+
+ convert_dl_to_table(attributes)
+
+ tabs = at_css('.tabs')
+ tabs.remove unless tabs.nil? || tabs.parent['class'] == 'membersList'
end
def format_members
@@ -138,7 +141,7 @@ module Docs
id = element['id']
element.remove_attribute('id')
- header['id'] = id
+ header['id'] = id unless id.nil?
annotations = element.at_css('.annotations')
annotations.name = 'small'
@@ -158,6 +161,10 @@ module Docs
dd.remove
end
+ # Format attributes as a table
+ dl = element.at_css('.attributes')
+ convert_dl_to_table(dl) unless dl.nil?
+
# Remove the unnecessary wrapper element
element.replace(element.inner_html)
end
@@ -176,6 +183,26 @@ module Docs
end
end
+ def convert_dl_to_table(dl)
+ table = Nokogiri::XML::Node.new('table', doc)
+ table['class'] = 'attributes'
+
+ dl.css('> dt').each do |dt|
+ dd = dt.next_element
+ has_dd = dd.name == 'dd' rescue false
+
+ tr = Nokogiri::XML::Node.new('tr', doc)
+ colspan = has_dd ? '' : ' colspan="2"' # handle <dt> without following <dt>
+ tr.add_child("<th#{colspan}>#{dt.inner_html.sub(/:$/, '')}</th>")
+
+ tr.add_child("<td>#{dd.inner_html}</td>") if has_dd
+
+ table.add_child(tr)
+ end
+
+ dl.replace(table)
+ end
+
end
end
end
diff --git a/lib/docs/scrapers/scala.rb b/lib/docs/scrapers/scala.rb
index 39e95121..dcf28b63 100644
--- a/lib/docs/scrapers/scala.rb
+++ b/lib/docs/scrapers/scala.rb
@@ -26,7 +26,14 @@ module Docs
self.release = '3.1.1'
self.base_url = 'https://scala-lang.org/api/3.1.1/'
self.root_path = 'index.html'
- # options[:container] = '#main-content'
+
+ options[:skip_patterns] = [
+ # Ignore class names with include “#”, which cause issues with the scraper
+ /%23/,
+
+ # Ignore local links to the Java documentation created by a Scaladoc bug
+ /java\/lang/,
+ ]
html_filters.push 'scala/entries_v3', 'scala/clean_html_v3'
end
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]