From 1181bd7498c66a14698ed3baf68badf92938447f Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Mon, 9 Oct 2017 10:52:15 -0400 Subject: [PATCH] Decouple React Native scraper from React scraper --- assets/stylesheets/application-dark.css.scss | 2 +- assets/stylesheets/application.css.scss | 2 +- assets/stylesheets/pages/_react.scss | 13 ----- assets/stylesheets/pages/_react_native.scss | 9 ++++ lib/docs/filters/react_native/clean_html.rb | 51 ++++++++++++++++++++ lib/docs/filters/react_native/entries.rb | 18 +------ lib/docs/scrapers/react_native.rb | 10 ++-- 7 files changed, 67 insertions(+), 38 deletions(-) delete mode 100644 assets/stylesheets/pages/_react.scss create mode 100644 assets/stylesheets/pages/_react_native.scss diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index 239a4305..d480f720 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -79,7 +79,7 @@ 'pages/pug', 'pages/ramda', 'pages/rdoc', - 'pages/react', + 'pages/react_native', 'pages/redis', 'pages/rethinkdb', 'pages/rfc', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index ea9fd1b7..4fdc2a14 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -79,7 +79,7 @@ 'pages/pug', 'pages/ramda', 'pages/rdoc', - 'pages/react', + 'pages/react_native', 'pages/redis', 'pages/rethinkdb', 'pages/rfc', diff --git a/assets/stylesheets/pages/_react.scss b/assets/stylesheets/pages/_react.scss deleted file mode 100644 index 8547471f..00000000 --- a/assets/stylesheets/pages/_react.scss +++ /dev/null @@ -1,13 +0,0 @@ -._react { - > h2 { @extend %block-heading; } - > h3 { @extend %block-label, %label-blue; } - > h4 { @extend %block-label; } - - p code, li code { @extend %label; } - blockquote, .deprecated { @extend %note; } - .deprecated { @extend %note-orange; } - .deprecatedTitle { font-weight: $boldFontWeight; } - - span.platform { float: right; } - span.propType, span.platform { font-weight: normal; } -} diff --git a/assets/stylesheets/pages/_react_native.scss b/assets/stylesheets/pages/_react_native.scss new file mode 100644 index 00000000..ee4d1c67 --- /dev/null +++ b/assets/stylesheets/pages/_react_native.scss @@ -0,0 +1,9 @@ +._react_native { + @extend %simple; + + .deprecated { @extend %note, %note-orange; } + .deprecatedTitle { font-weight: $boldFontWeight; } + + span.platform { float: right; } + span.propType, span.platform { font-weight: normal; } +} diff --git a/lib/docs/filters/react_native/clean_html.rb b/lib/docs/filters/react_native/clean_html.rb index d403bde9..54c7a142 100644 --- a/lib/docs/filters/react_native/clean_html.rb +++ b/lib/docs/filters/react_native/clean_html.rb @@ -2,10 +2,61 @@ module Docs class ReactNative class CleanHtmlFilter < Filter def call + @doc = at_css('.inner-content, article.withtoc') + if root_page? + at_css('h1').content = 'React Native Documentation' css('h1 ~ *').remove end + css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').remove + + css('table h1', 'table h2', 'table h3').each do |node| + table = node + table = table.parent until table.name == 'table' + table.replace(node) + end + + css('a.anchor', 'a.hashref').each do |node| + node.parent['id'] ||= node['name'] || node['id'] + end + + css('.highlight').each do |node| + node.name = 'pre' + node.css('.gutter').remove + node['data-language'] = node.at_css('[data-lang]').try(:[], 'data-lang') || 'js' + node.content = node.content.strip + end + + css('table.highlighttable').each do |node| + node.replace(node.at_css('pre.highlight')) + end + + css('.prism').each do |node| + node.name = 'pre' + node['data-language'] = node['class'][/(?<=language\-)(\w+)/] + node.content = node.content + end + + css('blockquote > p:first-child').each do |node| + node.remove if node.content.strip == 'Note:' + end + + css('h3#props', 'h3#methods').each { |node| node.name = 'h2' } + css('h4.propTitle').each { |node| node.name = 'h3' } + + css('> div > div', '> div', 'div > span', '.props', '.prop').each do |node| + node.before(node.children).remove + end + + css('a pre', 'h3 .propType').each do |node| + node.name = 'code' + end + + css('a[target]').each do |node| + node.remove_attribute('target') + end + css('center > .button', 'p:contains("short survey")', 'iframe', '.embedded-simulator', '.deprecatedIcon').remove css('h4.methodTitle').each do |node| diff --git a/lib/docs/filters/react_native/entries.rb b/lib/docs/filters/react_native/entries.rb index a5489cd2..d2e96d75 100644 --- a/lib/docs/filters/react_native/entries.rb +++ b/lib/docs/filters/react_native/entries.rb @@ -1,7 +1,6 @@ module Docs class ReactNative class EntriesFilter < Docs::EntriesFilter - REPLACE_TYPES = { 'The Basics' => 'Getting Started', 'apis' => 'APIs', @@ -23,9 +22,7 @@ module Docs end def additional_entries - entries = [] - - css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each do |node| # react-native + css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each_with_object [] do |node, entries| name = node.children.find(&:text?).try(:content) next if name.blank? sep = node.content.include?('static') ? '.' : '#' @@ -35,19 +32,6 @@ module Docs id = node.at_css('.anchor')['name'] entries << [name, id] end - - css('.apiIndex a pre').each do |node| # relay - next unless node.parent['href'].start_with?('#') - id = node.parent['href'].remove('#') - name = node.content.strip - sep = name.start_with?('static') ? '.' : '#' - name.remove! %r{(abstract|static) } - name.sub! %r{\(.*\)}, '()' - name.prepend(self.name + sep) - entries << [name, id] - end - - entries end end end diff --git a/lib/docs/scrapers/react_native.rb b/lib/docs/scrapers/react_native.rb index e67f2612..14c2c6c7 100644 --- a/lib/docs/scrapers/react_native.rb +++ b/lib/docs/scrapers/react_native.rb @@ -1,8 +1,7 @@ module Docs - class ReactNative < React - self.name = 'React Native' + class ReactNative < UrlScraper self.slug = 'react_native' - self.type = 'react' + self.type = 'react_native' self.release = '0.49' self.base_url = 'https://facebook.github.io/react-native/docs/' self.root_path = 'getting-started.html' @@ -11,10 +10,9 @@ module Docs code: 'https://github.com/facebook/react-native' } - html_filters.replace 'react/entries', 'react_native/entries' - html_filters.push 'react_native/clean_html' + html_filters.push 'react_native/entries', 'react_native/clean_html' - options[:root_title] = 'React Native Documentation' + options[:container] = '.documentationContent' options[:skip_patterns] = [/\Asample\-/] options[:skip] = %w( videos.html