Skip to content

Commit 1181bd7

Browse files
committed
Decouple React Native scraper from React scraper
1 parent 6d580a9 commit 1181bd7

File tree

7 files changed

+67
-38
lines changed

7 files changed

+67
-38
lines changed

assets/stylesheets/application-dark.css.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
'pages/pug',
8080
'pages/ramda',
8181
'pages/rdoc',
82-
'pages/react',
82+
'pages/react_native',
8383
'pages/redis',
8484
'pages/rethinkdb',
8585
'pages/rfc',

assets/stylesheets/application.css.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
'pages/pug',
8080
'pages/ramda',
8181
'pages/rdoc',
82-
'pages/react',
82+
'pages/react_native',
8383
'pages/redis',
8484
'pages/rethinkdb',
8585
'pages/rfc',

assets/stylesheets/pages/_react.scss

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
._react_native {
2+
@extend %simple;
3+
4+
.deprecated { @extend %note, %note-orange; }
5+
.deprecatedTitle { font-weight: $boldFontWeight; }
6+
7+
span.platform { float: right; }
8+
span.propType, span.platform { font-weight: normal; }
9+
}

lib/docs/filters/react_native/clean_html.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,61 @@ module Docs
22
class ReactNative
33
class CleanHtmlFilter < Filter
44
def call
5+
@doc = at_css('.inner-content, article.withtoc')
6+
57
if root_page?
8+
at_css('h1').content = 'React Native Documentation'
69
css('h1 ~ *').remove
710
end
811

12+
css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').remove
13+
14+
css('table h1', 'table h2', 'table h3').each do |node|
15+
table = node
16+
table = table.parent until table.name == 'table'
17+
table.replace(node)
18+
end
19+
20+
css('a.anchor', 'a.hashref').each do |node|
21+
node.parent['id'] ||= node['name'] || node['id']
22+
end
23+
24+
css('.highlight').each do |node|
25+
node.name = 'pre'
26+
node.css('.gutter').remove
27+
node['data-language'] = node.at_css('[data-lang]').try(:[], 'data-lang') || 'js'
28+
node.content = node.content.strip
29+
end
30+
31+
css('table.highlighttable').each do |node|
32+
node.replace(node.at_css('pre.highlight'))
33+
end
34+
35+
css('.prism').each do |node|
36+
node.name = 'pre'
37+
node['data-language'] = node['class'][/(?<=language\-)(\w+)/]
38+
node.content = node.content
39+
end
40+
41+
css('blockquote > p:first-child').each do |node|
42+
node.remove if node.content.strip == 'Note:'
43+
end
44+
45+
css('h3#props', 'h3#methods').each { |node| node.name = 'h2' }
46+
css('h4.propTitle').each { |node| node.name = 'h3' }
47+
48+
css('> div > div', '> div', 'div > span', '.props', '.prop').each do |node|
49+
node.before(node.children).remove
50+
end
51+
52+
css('a pre', 'h3 .propType').each do |node|
53+
node.name = 'code'
54+
end
55+
56+
css('a[target]').each do |node|
57+
node.remove_attribute('target')
58+
end
59+
960
css('center > .button', 'p:contains("short survey")', 'iframe', '.embedded-simulator', '.deprecatedIcon').remove
1061

1162
css('h4.methodTitle').each do |node|

lib/docs/filters/react_native/entries.rb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Docs
22
class ReactNative
33
class EntriesFilter < Docs::EntriesFilter
4-
54
REPLACE_TYPES = {
65
'The Basics' => 'Getting Started',
76
'apis' => 'APIs',
@@ -23,9 +22,7 @@ def get_type
2322
end
2423

2524
def additional_entries
26-
entries = []
27-
28-
css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each do |node| # react-native
25+
css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each_with_object [] do |node, entries|
2926
name = node.children.find(&:text?).try(:content)
3027
next if name.blank?
3128
sep = node.content.include?('static') ? '.' : '#'
@@ -35,19 +32,6 @@ def additional_entries
3532
id = node.at_css('.anchor')['name']
3633
entries << [name, id]
3734
end
38-
39-
css('.apiIndex a pre').each do |node| # relay
40-
next unless node.parent['href'].start_with?('#')
41-
id = node.parent['href'].remove('#')
42-
name = node.content.strip
43-
sep = name.start_with?('static') ? '.' : '#'
44-
name.remove! %r{(abstract|static) }
45-
name.sub! %r{\(.*\)}, '()'
46-
name.prepend(self.name + sep)
47-
entries << [name, id]
48-
end
49-
50-
entries
5135
end
5236
end
5337
end

lib/docs/scrapers/react_native.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module Docs
2-
class ReactNative < React
3-
self.name = 'React Native'
2+
class ReactNative < UrlScraper
43
self.slug = 'react_native'
5-
self.type = 'react'
4+
self.type = 'react_native'
65
self.release = '0.49'
76
self.base_url = 'https://facebook.github.io/react-native/docs/'
87
self.root_path = 'getting-started.html'
@@ -11,10 +10,9 @@ class ReactNative < React
1110
code: 'https://github.com/facebook/react-native'
1211
}
1312

14-
html_filters.replace 'react/entries', 'react_native/entries'
15-
html_filters.push 'react_native/clean_html'
13+
html_filters.push 'react_native/entries', 'react_native/clean_html'
1614

17-
options[:root_title] = 'React Native Documentation'
15+
options[:container] = '.documentationContent'
1816
options[:skip_patterns] = [/\Asample\-/]
1917
options[:skip] = %w(
2018
videos.html

0 commit comments

Comments
 (0)