History

Merge pull request #1475 from MasterEnoc/openjdk

Fix Openjdk additional entries and style

Simon Legner committed 5 years ago

Commit 06dbf8a2 parents dfed09b 288098b5 files · +52 −38Browse files

Unified · Split

5 files
  1. lib/docs/filters/openjdk/clean_html.rb +6 −8
  2. lib/docs/filters/openjdk/clean_html_new.rb +8 −9
  3. lib/docs/filters/openjdk/entries.rb +25 −10
  4. lib/docs/filters/openjdk/entries_new.rb +8 −10
  5. lib/docs/scrapers/openjdk.rb +5 −1
lib/docs/filters/openjdk/clean_html.rb+6−8
@@ -5,14 +5,14 @@ module Docs · 4 unmodified lines
55 class Openjdk
66 class CleanHtmlFilter < Filter
77 def call
8− css('.topNav', '.subNav', '.bottomNav', '.legalCopy', 'noscript', '.subTitle').remove
8+ css('.topNav', '.subNav', '.bottomNav', '.legalCopy', 'noscript', '.subTitle', 'hr').remove
99
1010 # Preserve internal fragment links
1111 # Transform <a name="foo"><!-- --></a><bar>text</bar>
1212 # into <bar id="foo">text</bar>
13− css('a[name]').each do |node|
13+ css('a[name]','a[id]').each do |node|
1414 if node.children.all?(&:blank?)
15− node.next_element['id'] = node['name'] if node.next_element
15+ node.next_element['id'] = (node['id'] || node['name'])if node.next_element
1616 node.remove
1717 end
1818 end
@@ -23,11 +23,9 @@ module Docs · 4 unmodified lines
2323 node.remove
2424 end
2525
26− # Replace summary tables with their detail content
27− css('h3[id$=".summary"]').each do |node|
28− id = node['id'].sub('summary', 'detail')
29− detail = at_css("h3[id='#{id}']") || at_css("h3[id='#{id.remove('optional.').remove('required.')}']")
30− node.parent.children = detail.parent.children if detail
26+ # remove captions in tables
27+ css('table caption').each do |node|
28+ node.remove
3129 end
3230
3331 css('h3[id$=".summary"]', 'h3[id$=".detail"]').each do |node|
lib/docs/filters/openjdk/clean_html_new.rb+8−9
@@ -7,15 +7,7 @@ module Docs · 6 unmodified lines
77 at_css('h1').content = "OpenJDK #{release} Documentation"
88 end
99
10− css('.header .sub-title').remove
11−
12− css('blockquote pre').each do |node|
13− node.parent.name = 'pre'
14− node.parent['class'] = 'highlight'
15− node.parent['data-language'] = 'java'
16− node.parent.content = node.content
17− node.remove
18− end
10+ css('.header .sub-title', 'hr', '.table-tabs').remove
1911
2012 # fix ul section that contains summaries or tables
2113 css('ul').each do |node|
@@ -24,6 +16,13 @@ module Docs · 2 unmodified lines
2416 end
2517 end
2618
19+ css('ul.summary-list').each do |node|
20+ node.css('li').each do |subnode|
21+ subnode.name = 'div'
22+ end
23+ node.name = 'div'
24+ end
25+
2726 # add syntax highlight to code blocks
2827 css('pre > code').each do |node|
2928 node.parent['class'] = 'lang-java'
lib/docs/filters/openjdk/entries.rb+25−10
@@ -29,16 +29,31 @@ module Docs · 28 unmodified lines
2929 def additional_entries
3030 # Only keep the first found entry with a unique name,
3131 # i.e. overloaded methods are skipped in index
32− css('a[name$=".summary"]').each_with_object({}) do |summary, entries|
33− next if summary['name'].include?('nested') || summary['name'].include?('constructor') ||
34− summary['name'].include?('field') || summary['name'].include?('constant')
35− summary.parent.css('.memberNameLink a').each do |node|
36− name = node.parent.parent.content.strip
37− name.sub! %r{\(.+?\)}m, '()'
38− id = node['href'].remove(%r{.*#})
39− entries[name] ||= ["#{self.name}.#{name}", id]
40− end
41− end.values
32+ if version == '8' || version == '8 Gui' || version == '8 Web'
33+ css('a[name$=".summary"]').each_with_object({}) do |summary, entries|
34+ next if summary['name'].include?('nested') || summary['name'].include?('constructor') ||
35+ summary['name'].include?('field') || summary['name'].include?('constant')
36+ summary.parent.css('.memberNameLink a').each do |node|
37+ name = node.parent.parent.content.strip
38+ name.sub! %r{\(.+?\)}m, '()'
39+ id = node['href'].remove(%r{.*#})
40+ entries[name] ||= ["#{self.name}.#{name}", id]
41+ end
42+ end.values
43+
44+ else
45+ css('a[id$=".summary"]').each_with_object({}) do |summary, entries|
46+ next if summary['id'].include?('nested') || summary['id'].include?('constructor') ||
47+ summary['id'].include?('field') || summary['id'].include?('constant')
48+ summary.parent.css('.memberNameLink a').each do |node|
49+ name = node.parent.parent.content.strip
50+ name.sub! %r{\(.+?\)}m, '()'
51+ id = node['href'].remove(%r{.*#})
52+ entries[name] ||= ["#{self.name}.#{name}", id]
53+ end
54+ end.values
55+ end
56+
4257 end
4358 end
4459 end
lib/docs/filters/openjdk/entries_new.rb+8−10
@@ -28,16 +28,14 @@ module Docs · 27 unmodified lines
2828 end
2929
3030 def additional_entries
31− css('a[name$=".summary"]').each_with_object({}) do |summary, entries|
32− next if summary['name'].include?('nested') || summary['name'].include?('constructor') ||
33− summary['name'].include?('field') || summary['name'].include?('constant')
34− summary.parent.css('.memberNameLink a').each do |node|
35− name = node.parent.parent.content.strip
36− name.sub! %r{\(.+?\)}m, '()'
37− id = node['href'].remove(%r{.*#})
38− entries[name] ||= ["#{self.name}.#{name}", id]
39− end
40− end.values
31+ entries = []
32+
33+ css('section[id]').each do |node|
34+ next if !(node['id'].match?(/\(/))
35+ entries << [self.name+ '.' +node.at_css('h3').content + '()', node['id']]
36+ end
37+
38+ entries
4139 end
4240
4341 end
lib/docs/scrapers/openjdk.rb+5−1
@@ -22,7 +22,10 @@ module Docs · 21 unmodified lines
2222 /\.png/
2323 ]
2424
25− options[:only_patterns] = [/\Ajava\./]
25+ options[:only_patterns] = [
26+ /\Ajava\./,
27+ /\Ajdk\./
28+ ]
2629
2730 options[:attribution] = <<-HTML
2831 &copy; 1993, 2020, Oracle and/or its affiliates. All rights reserved.<br>
@@ -37,6 +40,7 @@ module Docs · 8 unmodified lines
3740 version '15' do
3841 self.release = '15.0.1'
3942 self.root_path = 'index.html'
43+ self.base_url = 'https://docs.oracle.com/en/java/javase/15/docs/api/'
4044
4145 html_filters.push NEWFILTERS
4246