| @@ -0,0 +1,53 @@ |
| 1 | +module Docs |
| 2 | + class ReactNative |
| 3 | + class EntriesFilter < Docs::EntriesFilter |
| 4 | + |
| 5 | + REPLACE_TYPES = { |
| 6 | + 'The Basics' => 'Getting Started', |
| 7 | + 'apis' => 'APIs', |
| 8 | + 'components' => 'Components' |
| 9 | + } |
| 10 | + |
| 11 | + def get_name |
| 12 | + at_css('h1').children.select(&:text?).map(&:content).join.strip |
| 13 | + end |
| 14 | + |
| 15 | + def get_type |
| 16 | + link = at_css('.nav-docs-section .active, .toc .active') |
| 17 | + return 'Miscellaneous' unless link |
| 18 | + section = link.ancestors('.nav-docs-section, section').first |
| 19 | + type = section.at_css('h3').content.strip |
| 20 | + type = REPLACE_TYPES[type] || type |
| 21 | + type += ": #{name}" if type == 'Components' |
| 22 | + type |
| 23 | + end |
| 24 | + |
| 25 | + def additional_entries |
| 26 | + entries = [] |
| 27 | + |
| 28 | + css('.props > .prop > .propTitle', '.props > .prop > .methodTitle').each do |node| # react-native |
| 29 | + name = node.children.find(&:text?).try(:content) |
| 30 | + next if name.blank? |
| 31 | + sep = node.content.include?('static') ? '.' : '#' |
| 32 | + name.prepend(self.name + sep) |
| 33 | + name << '()' if node['class'].include?('methodTitle') |
| 34 | + id = node.at_css('.anchor')['name'] |
| 35 | + entries << [name, id] |
| 36 | + end |
| 37 | + |
| 38 | + css('.apiIndex a pre').each do |node| # relay |
| 39 | + next unless node.parent['href'].start_with?('#') |
| 40 | + id = node.parent['href'].remove('#') |
| 41 | + name = node.content.strip |
| 42 | + sep = name.start_with?('static') ? '.' : '#' |
| 43 | + name.remove! %r{(abstract|static) } |
| 44 | + name.sub! %r{\(.*\)}, '()' |
| 45 | + name.prepend(self.name + sep) |
| 46 | + entries << [name, id] |
| 47 | + end |
| 48 | + |
| 49 | + entries |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | +end |