| @@ -1,69 +1,33 @@ |
| 1 | module Docs | 1 | module Docs |
| 2 | class React | 2 | class React |
| 3 | class EntriesFilter < Docs::EntriesFilter | 3 | 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_name | 4 | def get_name |
| 19 | at_css('h1').children.select(&:text?).map(&:content).join.strip | 5 | at_css('h1').children.select(&:text?).map(&:content).join.strip |
| 20 | end | 6 | end |
| 21 | | 7 | |
| 22 | def get_type | 8 | 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').first | 10 | section = link.ancestors('.nav-docs-section, section').first |
| 26 | type = section.at_css('h3').content.strip | 11 | type = section.at_css('h3').content.strip |
| 27 | type = REPLACE_TYPES[type] || type | | |
| 28 | type += ": #{name}" if type == 'Components' | | |
| 29 | type | 12 | type |
| 30 | end | 13 | end |
| 31 | | 14 | |
| 32 | def additional_entries | 15 | 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.content | 18 | 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 | end | 24 | 'Reference: Component' |
| 42 | else | 25 | elsif slug == 'react-api' |
| 43 | entries = [] | 26 | 'Reference: React' |
| 44 | | 27 | else |
| 45 | css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each do |node| # react-native | 28 | '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 | end | 29 | 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 | end | 31 | end |
| 68 | end | 32 | end |
| 69 | end | 33 | end |