Skip to content

Commit ade1961

Browse files
author
dorimon
committed
Add vertx docs
1 parent b1c4af4 commit ade1961

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

lib/docs/filters/vertx/clean_html.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module Docs
2+
class Vertx
3+
class CleanHtmlFilter < Filter
4+
def call
5+
css('hr', 'header', 'nav', '.navbar', '.topbar').remove
6+
xpath('//*[@id="docs-layout"]/div/div[3]').remove
7+
xpath('//*[@id="docs-layout"]/div/div[1]').remove
8+
xpath('//main/div[last()]').remove
9+
xpath('//main/div[1]').remove
10+
xpath('//footer').remove
11+
css('#changelog').remove if root_page?
12+
13+
# Set id attributes on <h3> instead of an empty <a>
14+
css('h3').each do |node|
15+
anchor = node.at_css('a')
16+
node['id'] = anchor['id'] if anchor && anchor['id']
17+
end
18+
19+
# Make proper table headers
20+
css('td.header').each do |node|
21+
node.name = 'th'
22+
end
23+
24+
# Remove code highlighting
25+
css('pre').each do |node|
26+
node.content = node.content
27+
end
28+
29+
# ❗ Skip <img> tags with data: URIs
30+
css('img').each do |img|
31+
src = img['src']
32+
img.remove if src&.start_with?('data:')
33+
end
34+
35+
doc
36+
end
37+
end
38+
end
39+
end
40+

lib/docs/filters/vertx/entries.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module Docs
2+
class Vertx
3+
class EntriesFilter < Docs::EntriesFilter
4+
# Determines the default name of the page entry
5+
def get_name
6+
node = at_css('h1')
7+
return nil unless node
8+
9+
result = node.content.strip
10+
result = "v5.0.0 - #{result}" if slug.include?('5.0.0')
11+
result << ' event' if type == 'Events'
12+
result << '()' if node['class'].to_s.include?('function')
13+
result
14+
end
15+
16+
# Determines the type of the default entry (used for sidebar grouping)
17+
def get_type
18+
return nil if root_page?
19+
20+
node = at_xpath('/html/body/div/div/div[2]/main/div[1]/div[1]')
21+
node ? node.text.strip : 'Miscellaneous'
22+
end
23+
24+
# Returns additional entries from subheadings (usually <h2>)
25+
def additional_entries
26+
# return [] if root_page?
27+
#
28+
# css('h2').map do |node|
29+
# name = node.content.strip
30+
# id = node['id']
31+
# [name, id, type]
32+
# end
33+
[]
34+
end
35+
36+
# Determines whether to include the default entry for the page
37+
def include_default_entry?
38+
!at_css('.obsolete')
39+
end
40+
end
41+
end
42+
end
43+

lib/docs/scrapers/vertx.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
module Docs
3+
class Vertx < UrlScraper
4+
self.type = 'vertx'
5+
self.links = {
6+
home: 'http://vertx.io',
7+
code: 'https://github.com/eclipse-vertx/vert.x'
8+
}
9+
10+
html_filters.push 'vertx/entries', 'vertx/clean_html'
11+
12+
self.base_url = 'https://vertx.io/'
13+
self.root_path = 'docs'
14+
options[:attribution] = <<-HTML
15+
by Dor Sahar :)
16+
HTML
17+
18+
options[:skip_patterns] = [
19+
/api/,
20+
/apidocs/,
21+
/blog/,
22+
]
23+
24+
end
25+
end

public/icons/docs/vertx/16.png

855 Bytes
Loading
2.03 KB
Loading

0 commit comments

Comments
 (0)