Skip to content

Commit 5da0214

Browse files
committed
Add RxJS
The current RxJS documentation site is https://rxjs.dev/. It is very similar to Angular documentation site (https://angular.io/) so I reused most code. Images on the documentation site seem to be broken and so the scrapper cannot download them. You can see an example of a broken image at https://rxjs.dev/api/operators/buffer. Related to #939
1 parent b2608bb commit 5da0214

File tree

8 files changed

+244
-0
lines changed

8 files changed

+244
-0
lines changed

assets/stylesheets/application.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
'pages/rfc',
9595
'pages/rubydoc',
9696
'pages/rust',
97+
'pages/rxjs',
9798
'pages/sinon',
9899
'pages/socketio',
99100
'pages/sphinx',

assets/stylesheets/pages/_rxjs.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
._rxjs {
2+
@extend %simple;
3+
4+
.pre-title { @extend %pre-heading; }
5+
6+
.breadcrumbs { @extend %note; }
7+
.banner { @extend %note-green; }
8+
code.stable { @extend %label-green; }
9+
code.experimental { @extend %label-orange; }
10+
code.deprecated { @extend %label-red; }
11+
.alert.is-important { @extend %note-red; }
12+
.alert.is-helpful, .breadcrumbs { @extend %note-blue; }
13+
14+
.breadcrumbs { padding-left: 2em; }
15+
16+
img { margin: 1em 0; }
17+
18+
.location-badge {
19+
font-style: italic;
20+
text-align: right;
21+
}
22+
23+
td h3 { margin: 0 !important; }
24+
}

lib/docs/filters/rxjs/clean_html.rb

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
module Docs
2+
class Rxjs
3+
class CleanHtmlFilter < Filter
4+
def call
5+
if root_page?
6+
css('.card-container').remove
7+
at_css('h1').content = 'RxJS Documentation'
8+
end
9+
10+
css('br', 'hr', '.material-icons', '.header-link', '.breadcrumb').remove
11+
12+
css('.content', 'article', '.api-header', 'section', '.instance-member').each do |node|
13+
node.before(node.children).remove
14+
end
15+
16+
css('label', 'h2 > em', 'h3 > em').each do |node|
17+
node.name = 'code'
18+
end
19+
20+
css('h1 + code').each do |node|
21+
node.before('<p></p>')
22+
while node.next_element.name == 'code'
23+
node.previous_element << ' '
24+
node.previous_element << node.next_element
25+
end
26+
node.previous_element.prepend_child(node)
27+
end
28+
29+
css('td h3', '.l-sub-section > h3', '.alert h3', '.row-margin > h3', '.api-heading ~ h3', '.api-heading + h2', '.metadata-member h3').each do |node|
30+
node.name = 'h4'
31+
end
32+
33+
css('.l-sub-section', '.alert', '.banner').each do |node|
34+
node.name = 'blockquote'
35+
end
36+
37+
css('.file').each do |node|
38+
node.content = node.content.strip
39+
end
40+
41+
css('.filetree .children').each do |node|
42+
node.css('.file').each do |n|
43+
n.content = " #{n.content}"
44+
end
45+
end
46+
47+
css('.filetree').each do |node|
48+
node.content = node.css('.file').map(&:inner_html).join("\n")
49+
node.name = 'pre'
50+
node.remove_attribute('class')
51+
end
52+
53+
css('pre').each do |node|
54+
node.content = node.content.strip
55+
56+
node['data-language'] = 'typescript' if node['path'].try(:ends_with?, '.ts')
57+
node['data-language'] = 'html' if node['path'].try(:ends_with?, '.html')
58+
node['data-language'] = 'css' if node['path'].try(:ends_with?, '.css')
59+
node['data-language'] = 'js' if node['path'].try(:ends_with?, '.js')
60+
node['data-language'] = 'json' if node['path'].try(:ends_with?, '.json')
61+
node['data-language'] = node['language'].sub(/\Ats/, 'typescript').strip if node['language']
62+
node['data-language'] ||= 'typescript' if node.content.start_with?('@')
63+
64+
node.before(%(<div class="pre-title">#{node['title']}</div>)) if node['title']
65+
66+
if node['class'] && node['class'].include?('api-heading')
67+
node.name = 'h3'
68+
node.inner_html = "<code>#{node.inner_html}</code>"
69+
end
70+
71+
node.remove_attribute('path')
72+
node.remove_attribute('region')
73+
node.remove_attribute('linenums')
74+
node.remove_attribute('title')
75+
node.remove_attribute('language')
76+
node.remove_attribute('hidecopy')
77+
node.remove_attribute('class')
78+
end
79+
80+
css('h1[class]').remove_attr('class')
81+
css('table[class]').remove_attr('class')
82+
css('table[width]').remove_attr('width')
83+
css('tr[style]').remove_attr('style')
84+
85+
if at_css('.api-type-label.module')
86+
at_css('h1').content = subpath.remove('api/')
87+
end
88+
89+
css('th h3').each do |node|
90+
node.name = 'span'
91+
end
92+
93+
css('code code').each do |node|
94+
node.before(node.children).remove
95+
end
96+
97+
doc
98+
end
99+
end
100+
end
101+
end

lib/docs/filters/rxjs/entries.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Docs
2+
class Rxjs
3+
class EntriesFilter < Docs::EntriesFilter
4+
def get_name
5+
name = at_css('h1').content
6+
name.prepend "#{$1}. " if subpath =~ /\-pt(\d+)/
7+
name
8+
end
9+
10+
def get_type
11+
if slug.start_with?('guide')
12+
'Guide'
13+
elsif at_css('.api-type-label.module')
14+
name.split('/').first
15+
elsif slug.start_with?('api/')
16+
slug.split('/').second
17+
else
18+
'Miscellaneous'
19+
end
20+
end
21+
end
22+
end
23+
end

lib/docs/scrapers/rxjs.rb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
require 'yajl/json_gem'
2+
3+
module Docs
4+
class Rxjs < UrlScraper
5+
self.name = 'RxJS'
6+
self.type = 'rxjs'
7+
self.links = {
8+
home: 'https://rxjs.dev/',
9+
code: 'https://github.com/ReactiveX/rxjs'
10+
}
11+
12+
options[:max_image_size] = 256_000
13+
14+
options[:attribution] = <<-HTML
15+
&copy; 2015&ndash;2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.<br>
16+
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
17+
HTML
18+
19+
module Common
20+
private
21+
22+
def initial_urls
23+
initial_urls = []
24+
25+
Request.run "#{self.class.base_url}generated/navigation.json" do |response|
26+
data = JSON.parse(response.body)
27+
dig = ->(entry) do
28+
initial_urls << url_for("generated/docs/#{entry['url']}.json") if entry['url'] && entry['url'] != 'api'
29+
entry['children'].each(&dig) if entry['children']
30+
end
31+
data['SideNav'].each(&dig)
32+
end
33+
34+
Request.run "#{self.class.base_url}generated/docs/api/api-list.json" do |response|
35+
data = JSON.parse(response.body)
36+
dig = ->(entry) do
37+
initial_urls << url_for("generated/docs/#{entry['path']}.json") if entry['path']
38+
initial_urls << url_for("generated/docs/api/#{entry['name']}.json") if entry['name'] && !entry['path']
39+
entry['items'].each(&dig) if entry['items']
40+
end
41+
data.each(&dig)
42+
end
43+
44+
initial_urls
45+
end
46+
47+
def handle_response(response)
48+
if response.mime_type.include?('json')
49+
begin
50+
response.options[:response_body] = JSON.parse(response.body)['contents']
51+
rescue JSON::ParserError
52+
response.options[:response_body] = ''
53+
end
54+
response.headers['Content-Type'] = 'text/html'
55+
response.url.path = response.url.path.sub('/generated/docs/', '/').remove('.json')
56+
response.effective_url.path = response.effective_url.path.sub('/generated/docs/', '/').remove('.json')
57+
end
58+
super
59+
end
60+
end
61+
62+
version do
63+
self.release = '6.3.3'
64+
self.base_url = 'https://rxjs.dev/'
65+
self.root_path = 'guide/overview'
66+
67+
html_filters.push 'rxjs/clean_html', 'rxjs/entries'
68+
69+
options[:follow_links] = false
70+
options[:only_patterns] = [/\Aguide/, /\Aapi/]
71+
options[:fix_urls_before_parse] = ->(url) do
72+
url.sub! %r{\Aguide/}, '/guide/'
73+
url.sub! %r{\Aapi/}, '/api/'
74+
url.sub! %r{\Agenerated/}, '/generated/'
75+
url
76+
end
77+
78+
include Docs::Rxjs::Common
79+
end
80+
81+
private
82+
83+
def parse(response)
84+
response.body.gsub! '<code-example', '<pre'
85+
response.body.gsub! '</code-example', '</pre'
86+
response.body.gsub! '<code-pane', '<pre'
87+
response.body.gsub! '</code-pane', '</pre'
88+
response.body.gsub! '<live-example></live-example>', 'live example'
89+
response.body.gsub! '<live-example', '<span'
90+
response.body.gsub! '</live-example', '</span'
91+
super
92+
end
93+
end
94+
end

public/icons/docs/rxjs/16.png

5.23 KB
Loading
4.96 KB
Loading

public/icons/docs/rxjs/SOURCE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://reactivex.io/

0 commit comments

Comments
 (0)