Skip to content

Commit 5305664

Browse files
authored
Merge branch 'main' into update-tooling
2 parents d2808d7 + bef2edf commit 5305664

File tree

5 files changed

+445
-457
lines changed

5 files changed

+445
-457
lines changed

lib/pebble_documentation_pebblekit_android.rb

Lines changed: 90 additions & 46 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
75-
html = process_html(html, url)
105+
html = summary.at_css('#class-summary').to_html
106+
html = process_html(html, url, is_package: true)
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,42 +155,57 @@ 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

154193
def name_to_url(name)
155194
name.split('.').join('/')
156195
end
157196

158-
def process_html(html, root)
197+
def process_html(html, root, is_package: false)
159198
contents = Nokogiri::HTML(html)
160-
contents.css('a').each do | link |
161-
next if link['href'].nil?
162-
href = File.expand_path(link['href'], root)
163-
href = href.sub('/com/com/', '/com/')
164-
href = href.sub('.html', '/')
199+
contents.css('a').each do |link|
200+
href = link['href']
201+
next if href.nil?
202+
203+
unless href.start_with?('https://')
204+
href = "../#{href}" unless is_package or href.start_with?('#')
205+
href = File.expand_path(href, root)
206+
.sub('/com/com/', '/com/')
207+
.sub('.html', '/')
208+
end
165209
link['href'] = href
166210
end
167211
contents.css('.memberSummary caption').remove
@@ -170,24 +214,24 @@ def process_html(html, root)
170214
end
171215

172216
class PageDocPebbleKitAndroid < Jekyll::Page
173-
def initialize(site, base, dir, title, contents, group)
217+
def initialize(site, dir, title, contents, group)
174218
@site = site
175-
@base = base
219+
@base = site.source
176220
@dir = dir
177221
@name = 'index.html'
178222
@contents = contents
179223
@group = group
180224

181225
process(@name)
182-
read_yaml(File.join(base, '_layouts', 'docs'), 'pebblekit-android.html')
226+
read_yaml(File.join(@base, '_layouts', 'docs'), 'pebblekit-android.html')
183227
data['title'] = title.to_s
184228
end
185229

186230
def to_liquid(attrs = ATTRIBUTES_FOR_LIQUID)
187-
super(attrs + %w(
231+
super(attrs + %w[
188232
contents
189233
group
190-
))
234+
])
191235
end
192236

193237
attr_reader :contents

plugins/generator_docs.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ def generate_docs
8181
generate_docs_c_preview unless @site.data['docs']['c_preview'].nil?
8282
generate_docs_rocky_js
8383
generate_docs_pebblekit_js
84-
# TODO: probably remove these, we don't have the source for these docs :(
85-
# generate_docs_pebblekit_android
86-
# generate_docs_pebblekit_ios
84+
generate_docs_pebblekit_android
85+
generate_docs_pebblekit_ios
8786
end
8887

8988
def render_pages

0 commit comments

Comments
 (0)