History

Update React documentation (15.4.0)

Thibaut Courouble committed 9 years ago

Commit 008e85c1 parent e5356243 files · +29 −62Browse files

Unified · Split

3 files
  1. lib/docs/filters/react/clean_html.rb +1 −1
  2. lib/docs/filters/react/entries.rb +14 −50
  3. lib/docs/scrapers/react.rb +14 −11
lib/docs/filters/react/clean_html.rb+1−1
@@ -8,7 +8,7 @@ module Docs · 7 unmodified lines
8 at_css('h1').content = context[:root_title]8 at_css('h1').content = context[:root_title]
9 end9 end
10 10
11 css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide').remove11 css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').remove
12 12
13 css('table h1', 'table h2', 'table h3').each do |node|13 css('table h1', 'table h2', 'table h3').each do |node|
14 table = node14 table = node
lib/docs/filters/react/entries.rb+14−50
@@ -1,69 +1,33 @@
1module Docs1module Docs
2 class React2 class React
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 API_SLUGS = %w(
5 docs/top-level-api
6 docs/component-api
7 docs/component-specs
8 )
9
10 REPLACE_TYPES = {
11 'Quick Start' => 'Guides',
12 'User Guide' => 'Guides',
13 'The Basics' => 'Getting Started',
14 'apis' => 'APIs',
15 'components' => 'Components'
16 }
17
18 def get_name4 def get_name
19 at_css('h1').children.select(&:text?).map(&:content).join.strip5 at_css('h1').children.select(&:text?).map(&:content).join.strip
20 end6 end
21 7
22 def get_type8 def get_type
23 link = at_css('.nav-docs-section .active, .toc .active')9 link = at_css('.nav-docs-section .active, .toc .active')
24 return 'Miscellaneous' unless link
25 section = link.ancestors('.nav-docs-section, section').first10 section = link.ancestors('.nav-docs-section, section').first
26 type = section.at_css('h3').content.strip11 type = section.at_css('h3').content.strip
27 type = REPLACE_TYPES[type] || type
28 type += ": #{name}" if type == 'Components'
29 type12 type
30 end13 end
31 14
32 def additional_entries15 def additional_entries
33 if API_SLUGS.include?(slug)16 css('.inner-content h3 code, .inner-content h4 code').each_with_object([]) do |node, entries|
34 css('.inner-content h3, .inner-content h4').map do |node|17 name = node.content
35 name = node.content18 name.remove! %r{[#\(\)]}
36 name.remove! %r{[#\(\)]}19 name.remove! %r{\w+\:}
37 name.remove! %r{\w+\:}20 name.strip!
38 id = node.at_css('.anchor')['name']21 name = 'createFragmentobject' if name.include?('createFragmentobject')
39 type = slug.include?('component') ? 'Component' : 'React'22 id = node.parent.at_css('.anchor')['name']
40 [name, id, type]23 type = if slug == 'react-component'
41 end24 'Reference: Component'
42 else25 elsif slug == 'react-api'
43 entries = []26 'Reference: React'
44 27 else
45 css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each do |node| # react-native28 'Reference'
46 name = node.children.find(&:text?).try(:content)
47 next if name.blank?
48 sep = node.content.include?('static') ? '.' : '#'
49 name.prepend(self.name + sep)
50 name << '()' if node['class'].include?('methodTitle')
51 id = node.at_css('.anchor')['name']
52 entries << [name, id]
53 end29 end
54 30 entries << [name, id, type]
55 css('.apiIndex a pre').each do |node| # relay
56 next unless node.parent['href'].start_with?('#')
57 id = node.parent['href'].remove('#')
58 name = node.content.strip
59 sep = name.start_with?('static') ? '.' : '#'
60 name.remove! %r{(abstract|static) }
61 name.sub! %r{\(.*\)}, '()'
62 name.prepend(self.name + sep)
63 entries << [name, id]
64 end
65
66 entries
67 end31 end
68 end32 end
69 end33 end
lib/docs/scrapers/react.rb+14−11
@@ -2,9 +2,9 @@ module Docs · 1 unmodified line
2 class React < UrlScraper2 class React < UrlScraper
3 self.name = 'React'3 self.name = 'React'
4 self.type = 'react'4 self.type = 'react'
5 self.release = '15.3.0'5 self.release = '15.4.0'
6 self.base_url = 'https://facebook.github.io/react/'6 self.base_url = 'https://facebook.github.io/react/docs/'
7 self.root_path = 'docs/getting-started.html'7 self.root_path = 'hello-world.html'
8 self.links = {8 self.links = {
9 home: 'https://facebook.github.io/react/',9 home: 'https://facebook.github.io/react/',
10 code: 'https://github.com/facebook/react'10 code: 'https://github.com/facebook/react'
@@ -14,14 +14,17 @@ module Docs · 3 unmodified lines
14 14
15 options[:root_title] = 'React Documentation'15 options[:root_title] = 'React Documentation'
16 options[:container] = '.documentationContent'16 options[:container] = '.documentationContent'
17 options[:only_patterns] = [/\Adocs\//, /\Atips\//]17
18 options[:skip] = %w(18 options[:replace_paths] = {
19 docs/19 'top-level-api.html' => 'react-api.html',
20 docs/videos.html20 'working-with-the-browser.html' => 'refs-and-the-dom.html',
21 docs/complementary-tools.html21 'interactivity-and-dynamic-uis.html' => 'state-and-lifecycle.html',
22 docs/examples.html22 'more-about-refs.html' => 'refs-and-the-dom.html',
23 docs/conferences.html23 'advanced-performance.html' => 'optimizing-performance.html',
24 tips/introduction.html)24 'component-api.html' => 'react-component.html',
25 'component-specs.html' => 'react-component.html',
26 'multiple-components.html' => 'composition-vs-inheritance.html',
27 }
25 28
26 options[:attribution] = <<-HTML29 options[:attribution] = <<-HTML
27 &copy; 2013&ndash;2016 Facebook Inc.<br>30 &copy; 2013&ndash;2016 Facebook Inc.<br>