Skip to content

Commit 0db3dd4

Browse files
committed
lib/docs_android: rework to parse javadocs from recent JDK versions
Signed-off-by: Ruby Iris Juric <[email protected]>
1 parent ae37ef1 commit 0db3dd4

File tree

1 file changed

+79
-39
lines changed

1 file changed

+79
-39
lines changed

lib/pebble_documentation_pebblekit_android.rb

Lines changed: 79 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,37 @@ class DocumentationPebbleKitAndroid < Documentation
2727
def initialize(site, source)
2828
super(site)
2929
@path = '/docs/pebblekit-android/'
30-
open(source) do | zf |
31-
Zip::File.open(zf.path) do | zipfile |
32-
entry = zipfile.glob('javadoc/overview-summary.html').first
30+
File.open(source) do |zf|
31+
Zip::File.open(zf.path) do |zipfile|
32+
entry = zipfile.glob('javadoc/index.html').first
3333
summary = Nokogiri::HTML(entry.get_input_stream.read)
3434
process_summary(zipfile, summary)
3535

36-
@pages << PageDocPebbleKitAndroid.new(@site, @site.source, 'docs/pebblekit-android/com/constant-values/', 'Constant Values', process_html(Nokogiri::HTML(zipfile.glob('javadoc/constant-values.html').first.get_input_stream.read).at_css('.constantValuesContainer').to_html, '/docs/pebblekit-android/'), nil)
37-
@pages << PageDocPebbleKitAndroid.new(@site, @site.source, 'docs/pebblekit-android/com/serialized-form/', 'Serialized Form', process_html(Nokogiri::HTML(zipfile.glob('javadoc/serialized-form.html').first.get_input_stream.read).at_css('.serializedFormContainer').to_html, '/docs/pebblekit-android/'), nil)
36+
@pages << PageDocPebbleKitAndroid.new(
37+
@site,
38+
'docs/pebblekit-android/com/constant-values/',
39+
'Constant Values',
40+
process_html(
41+
Nokogiri::HTML(zipfile.glob('javadoc/constant-values.html').first.get_input_stream.read)
42+
.at_css('.constants-summary')
43+
.to_html,
44+
'/docs/pebblekit-android/'
45+
),
46+
nil
47+
)
48+
49+
@pages << PageDocPebbleKitAndroid.new(
50+
@site,
51+
'docs/pebblekit-android/com/serialized-form/',
52+
'Serialized Form',
53+
process_html(
54+
Nokogiri::HTML(zipfile.glob('javadoc/serialized-form.html').first.get_input_stream.read)
55+
.at_css('.serialized-package-container')
56+
.to_html,
57+
'/docs/pebblekit-android/'
58+
),
59+
nil
60+
)
3861
end
3962
end
4063
end
@@ -46,8 +69,8 @@ def language
4669
end
4770

4871
def process_summary(zipfile, summary)
49-
summary.css('tbody tr').each do | row |
50-
name = row.at_css('td.colFirst').content
72+
summary.css('.summary-table .col-first.all-packages-table').each do |row|
73+
name = row.content
5174
package = {
5275
name: name,
5376
url: "#{@path}#{name_to_url(name)}/",
@@ -61,27 +84,34 @@ def process_summary(zipfile, summary)
6184
@tree << package
6285
end
6386

64-
@tree.each do | package |
87+
@tree.each do |package|
6588
entry = zipfile.glob("javadoc/#{name_to_url(package[:name])}/package-summary.html").first
6689
summary = Nokogiri::HTML(entry.get_input_stream.read)
6790
process_package(zipfile, package, summary)
6891
end
6992
end
7093

94+
def find_table(html, name)
95+
button = html.at_xpath("//button[text()=\"#{name}\"]")
96+
return [] unless button
97+
98+
selector = button['id']
99+
html.css(".col-first.#{selector}").zip(html.css(".col-last.#{selector}"))
100+
end
101+
71102
def process_package(zipfile, package, summary)
72103
url = "#{@path}#{name_to_url(package[:name])}"
73104

74-
html = summary.at_css('.contentContainer').to_html
105+
html = summary.at_css('#class-summary').to_html
75106
html = process_html(html, url)
76107

77-
@pages << PageDocPebbleKitAndroid.new(@site, @site.source, url, package[:name], html, package)
108+
@pages << PageDocPebbleKitAndroid.new(@site, url, package[:name], html, package)
78109

79-
class_table = summary.css('table[summary~="Class Summary"]')
80-
class_table.css('tbody tr').each do | row |
81-
name = row.at_css('td.colFirst').content
110+
find_table(summary, 'Classes').each do |row|
111+
name = row[0].content
82112
package[:children] << {
83113
name: name,
84-
summary: row.at_css('.colLast').content,
114+
summary: row[1].content,
85115
url: "#{url}/#{name}",
86116
path: package[:path].clone << name,
87117
type: 'class',
@@ -93,12 +123,11 @@ def process_package(zipfile, package, summary)
93123
add_symbol(name: "#{package[:name]}.#{name}", url: "#{url}/#{name}")
94124
end
95125

96-
enum_table = summary.css('table[summary~="Enum Summary"]')
97-
enum_table.css('tbody tr').each do | row |
98-
name = row.at_css('.colFirst').content
126+
find_table(summary, 'Enum Classes').each do |row|
127+
name = row[0].content
99128
package[:children] << {
100129
name: name,
101-
summary: row.at_css('.colLast').content,
130+
summary: row[1].content,
102131
path: package[:path].clone << name,
103132
url: "#{url}/#{name}",
104133
type: 'enum',
@@ -110,11 +139,11 @@ def process_package(zipfile, package, summary)
110139
add_symbol(name: "#{package[:name]}.#{name}", url: "#{url}/#{name}")
111140
end
112141

113-
summary.css('table[summary~="Exception Summary"]').css('tbody tr').each do | row |
114-
name = row.at_css('td.colFirst').content
142+
find_table(summary, 'Exceptions').each do |row|
143+
name = row[0].content
115144
package[:children] << {
116145
name: name,
117-
summary: row.at_css('.colLast').content,
146+
summary: row[1].content,
118147
path: package[:path].clone << name,
119148
url: "#{url}/#{name}",
120149
type: 'exception',
@@ -126,28 +155,38 @@ def process_package(zipfile, package, summary)
126155
add_symbol(name: "#{package[:name]}.#{name}", url: "#{url}/#{name}")
127156
end
128157

129-
package[:children].each do | child |
130-
filename = "javadoc/#{name_to_url(package[:name])}/#{child[:name]}.html"
131-
child_url = '/docs/pebblekit-android/' + package[:name].split('.').join('/') + '/' + child[:name] + '/'
158+
package[:children].each do |child|
159+
child_path = "#{name_to_url(package[:name])}/#{child[:name]}"
160+
filename = "javadoc/#{child_path}.html"
161+
child_url = "/docs/pebblekit-android/#{child_path}/"
132162

133163
entry = zipfile.glob(filename).first
134164
summary = Nokogiri::HTML(entry.get_input_stream.read)
135165

136-
method_table = summary.css('table[summary~="Method Summary"]')
137-
method_table.css('tr').each do | row |
138-
next unless row.at_css('.memberNameLink')
139-
name = row.at_css('.memberNameLink').content
166+
method_rows = summary.css('#method-summary-table .summary-table')
167+
method_table =
168+
method_rows.css('.col-second:not(.table-header)').zip(method_rows.css('.col-last:not(.table-header)'))
169+
170+
method_table.each do |row|
171+
link = row[0].at_css('.member-name-link')
172+
next unless link
173+
174+
name = link.content
175+
description = row[1].at_css('.block')
140176
child[:methods] << {
141177
name: name,
142-
summary: row.at_css('.block') ? row.at_css('.block').content : '',
143-
url: child_url + '#' + name,
178+
summary: description ? description.content : '',
179+
url: "#{child_url}##{name}",
144180
type: 'method'
145181
}
146-
add_symbol(name: [package[:name], child[:name], name].join('.'), url: child_url + '#' + name)
182+
add_symbol(name: "#{package[:name]}.#{child[:name]}.#{name}", url: "#{child_url}##{name}")
183+
end
184+
html = summary.at_css('main')
185+
html.children.each do |node|
186+
node.remove if node.classes.include?('header')
147187
end
148-
html = summary.at_css('.contentContainer').to_html
149-
html = process_html(html, child_url)
150-
@pages << PageDocPebbleKitAndroid.new(@site, @site.source, child_url, child[:name], html, child)
188+
html = process_html(html.to_html, child_url)
189+
@pages << PageDocPebbleKitAndroid.new(@site, child_url, child[:name], html, child)
151190
end
152191
end
153192

@@ -159,6 +198,7 @@ def process_html(html, root)
159198
contents = Nokogiri::HTML(html)
160199
contents.css('a').each do | link |
161200
next if link['href'].nil?
201+
162202
href = File.expand_path(link['href'], root)
163203
href = href.sub('/com/com/', '/com/')
164204
href = href.sub('.html', '/')
@@ -170,24 +210,24 @@ def process_html(html, root)
170210
end
171211

172212
class PageDocPebbleKitAndroid < Jekyll::Page
173-
def initialize(site, base, dir, title, contents, group)
213+
def initialize(site, dir, title, contents, group)
174214
@site = site
175-
@base = base
215+
@base = site.source
176216
@dir = dir
177217
@name = 'index.html'
178218
@contents = contents
179219
@group = group
180220

181221
process(@name)
182-
read_yaml(File.join(base, '_layouts', 'docs'), 'pebblekit-android.html')
222+
read_yaml(File.join(@base, '_layouts', 'docs'), 'pebblekit-android.html')
183223
data['title'] = title.to_s
184224
end
185225

186226
def to_liquid(attrs = ATTRIBUTES_FOR_LIQUID)
187-
super(attrs + %w(
227+
super(attrs + %w[
188228
contents
189229
group
190-
))
230+
])
191231
end
192232

193233
attr_reader :contents

0 commit comments

Comments
 (0)