Browse Source

Update React Native documentation (0.38)

Thibaut Courouble 9 years ago
parent
commit
7183d93bf5

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

@@ -3,7 +3,7 @@ module Docs
     class CleanHtmlFilter < Filter
       def call
         if root_page?
-          css('#unsupported + div + center', '#unsupported + div', '#unsupported', '.toggler', 'center > img').remove
+          css('h1 ~ *').remove
         end
 
         css('center > .button', 'p:contains("short survey")', 'iframe', '.embedded-simulator').remove

+ 53 - 0
lib/docs/filters/react_native/entries.rb

@@ -0,0 +1,53 @@
+module Docs
+  class ReactNative
+    class EntriesFilter < Docs::EntriesFilter
+
+      REPLACE_TYPES = {
+        '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
+        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]
+        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
+end

+ 2 - 2
lib/docs/scrapers/react_native.rb

@@ -3,7 +3,7 @@ module Docs
     self.name = 'React Native'
     self.slug = 'react_native'
     self.type = 'react'
-    self.release = '0.37'
+    self.release = '0.38'
     self.base_url = 'https://facebook.github.io/react-native/docs/'
     self.root_path = 'getting-started.html'
     self.links = {
@@ -11,10 +11,10 @@ module Docs
       code: 'https://github.com/facebook/react-native'
     }
 
+    html_filters.replace 'react/entries', 'react_native/entries'
     html_filters.push 'react_native/clean_html'
 
     options[:root_title] = 'React Native Documentation'
-    options[:only_patterns] = nil
     options[:skip_patterns] = [/\Asample\-/]
     options[:skip] = %w(
       videos.html