| @@ -1,69 +1,33 @@ |
| 1 | 1 | module Docs |
| 2 | 2 | class React |
| 3 | 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 | 4 | def get_name |
| 19 | 5 | at_css('h1').children.select(&:text?).map(&:content).join.strip |
| 20 | 6 | end |
| 21 | 7 | |
| 22 | 8 | def get_type |
| 23 | 9 | link = at_css('.nav-docs-section .active, .toc .active') |
| 24 | | − return 'Miscellaneous' unless link |
| 25 | 10 | section = link.ancestors('.nav-docs-section, section').first |
| 26 | 11 | type = section.at_css('h3').content.strip |
| 27 | | − type = REPLACE_TYPES[type] || type |
| 28 | | − type += ": #{name}" if type == 'Components' |
| 29 | 12 | type |
| 30 | 13 | end |
| 31 | 14 | |
| 32 | 15 | def additional_entries |
| 33 | | − if API_SLUGS.include?(slug) |
| 34 | | − css('.inner-content h3, .inner-content h4').map do |node| |
| 35 | | − name = node.content |
| 36 | | − name.remove! %r{[#\(\)]} |
| 37 | | − name.remove! %r{\w+\:} |
| 38 | | − id = node.at_css('.anchor')['name'] |
| 39 | | − type = slug.include?('component') ? 'Component' : 'React' |
| 40 | | − [name, id, type] |
| 41 | | − end |
| 42 | | − else |
| 43 | | − entries = [] |
| 44 | | − |
| 45 | | − css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each do |node| # react-native |
| 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] |
| 16 | + css('.inner-content h3 code, .inner-content h4 code').each_with_object([]) do |node, entries| |
| 17 | + name = node.content |
| 18 | + name.remove! %r{[#\(\)]} |
| 19 | + name.remove! %r{\w+\:} |
| 20 | + name.strip! |
| 21 | + name = 'createFragmentobject' if name.include?('createFragmentobject') |
| 22 | + id = node.parent.at_css('.anchor')['name'] |
| 23 | + type = if slug == 'react-component' |
| 24 | + 'Reference: Component' |
| 25 | + elsif slug == 'react-api' |
| 26 | + 'Reference: React' |
| 27 | + else |
| 28 | + 'Reference' |
| 53 | 29 | end |
| 54 | | − |
| 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 |
| 30 | + entries << [name, id, type] |
| 67 | 31 | end |
| 68 | 32 | end |
| 69 | 33 | end |