Browse Source

Update React documentation (15.4.0)

Thibaut Courouble 9 years ago
parent
commit
008e85c0fc
3 changed files with 29 additions and 62 deletions
  1. 1 1
      lib/docs/filters/react/clean_html.rb
  2. 14 50
      lib/docs/filters/react/entries.rb
  3. 14 11
      lib/docs/scrapers/react.rb

+ 1 - 1
lib/docs/filters/react/clean_html.rb

@@ -8,7 +8,7 @@ module Docs
           at_css('h1').content = context[:root_title]
         end
 
-        css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide').remove
+        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

+ 14 - 50
lib/docs/filters/react/entries.rb

@@ -1,69 +1,33 @@
 module Docs
   class React
     class EntriesFilter < Docs::EntriesFilter
-      API_SLUGS = %w(
-        docs/top-level-api
-        docs/component-api
-        docs/component-specs
-      )
-
-      REPLACE_TYPES = {
-        'Quick Start' => 'Guides',
-        'User Guide' => 'Guides',
-        'The Basics' => 'Getting Started',
-        'apis' => 'APIs',
-        'components' => 'Components'
-      }
-
       def get_name
         at_css('h1').children.select(&:text?).map(&:content).join.strip
       end
 
       def get_type
         link = at_css('.nav-docs-section .active, .toc .active')
-        return 'Miscellaneous' unless link
         section = link.ancestors('.nav-docs-section, section').first
         type = section.at_css('h3').content.strip
-        type = REPLACE_TYPES[type] || type
-        type += ": #{name}" if type == 'Components'
         type
       end
 
       def additional_entries
-        if API_SLUGS.include?(slug)
-          css('.inner-content h3, .inner-content h4').map do |node|
-            name = node.content
-            name.remove! %r{[#\(\)]}
-            name.remove! %r{\w+\:}
-            id = node.at_css('.anchor')['name']
-            type = slug.include?('component') ? 'Component' : 'React'
-            [name, id, type]
-          end
-        else
-          entries = []
-
-          css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each do |node| # react-native
-            name = node.children.find(&:text?).try(:content)
-            next if name.blank?
-            sep = node.content.include?('static') ? '.' : '#'
-            name.prepend(self.name + sep)
-            name << '()' if node['class'].include?('methodTitle')
-            id = node.at_css('.anchor')['name']
-            entries << [name, id]
+        css('.inner-content h3 code, .inner-content h4 code').each_with_object([]) do |node, entries|
+          name = node.content
+          name.remove! %r{[#\(\)]}
+          name.remove! %r{\w+\:}
+          name.strip!
+          name = 'createFragmentobject' if name.include?('createFragmentobject')
+          id = node.parent.at_css('.anchor')['name']
+          type = if slug == 'react-component'
+            'Reference: Component'
+          elsif slug == 'react-api'
+            'Reference: React'
+          else
+            'Reference'
           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
+          entries << [name, id, type]
         end
       end
     end

+ 14 - 11
lib/docs/scrapers/react.rb

@@ -2,9 +2,9 @@ module Docs
   class React < UrlScraper
     self.name = 'React'
     self.type = 'react'
-    self.release = '15.3.0'
-    self.base_url = 'https://facebook.github.io/react/'
-    self.root_path = 'docs/getting-started.html'
+    self.release = '15.4.0'
+    self.base_url = 'https://facebook.github.io/react/docs/'
+    self.root_path = 'hello-world.html'
     self.links = {
       home: 'https://facebook.github.io/react/',
       code: 'https://github.com/facebook/react'
@@ -14,14 +14,17 @@ module Docs
 
     options[:root_title] = 'React Documentation'
     options[:container] = '.documentationContent'
-    options[:only_patterns] = [/\Adocs\//, /\Atips\//]
-    options[:skip] = %w(
-      docs/
-      docs/videos.html
-      docs/complementary-tools.html
-      docs/examples.html
-      docs/conferences.html
-      tips/introduction.html)
+
+    options[:replace_paths] = {
+      'top-level-api.html' => 'react-api.html',
+      'working-with-the-browser.html' => 'refs-and-the-dom.html',
+      'interactivity-and-dynamic-uis.html' => 'state-and-lifecycle.html',
+      'more-about-refs.html' => 'refs-and-the-dom.html',
+      'advanced-performance.html' => 'optimizing-performance.html',
+      'component-api.html' => 'react-component.html',
+      'component-specs.html' => 'react-component.html',
+      'multiple-components.html' => 'composition-vs-inheritance.html',
+    }
 
     options[:attribution] = <<-HTML
       &copy; 2013&ndash;2016 Facebook Inc.<br>