Format attributes as a table

pull/1708/head
Nicolas Ettlin 3 years ago committed by Simon Legner
parent afe3a26c7a
commit 55ec2b6302

@ -3,9 +3,14 @@
.deprecated { @extend %label-red; }
.attributes dl,
.attributes pre {
margin: 0;
}
.related-types {
@extend %pre;
margin-top: 0;
margin: 0;
white-space: normal;
}

@ -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

@ -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

Loading…
Cancel
Save