History

Merge pull request #1399 from MasterEnoc/relay

Update Relay to 10.1.0

Simon Legner committed 5 years ago

Commit c93270d2 parents 296a7e0 e9322e43 files · +74 −69Browse files

Unified · Split

3 files
  1. lib/docs/filters/relay/clean_html.rb +22 −38
  2. lib/docs/filters/relay/entries.rb +32 −22
  3. lib/docs/scrapers/relay.rb +20 −9
lib/docs/filters/relay/clean_html.rb+22−38
@@ -2,58 +2,42 @@ module Docs · 1 unmodified line
2 class Relay2 class Relay
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 @doc = at_css('.inner-content, article.withtoc')
6 5
7 if root_page?6 if slug == 'index'
8 at_css('h1').content = 'Relay Documentation'7 css('img').remove
9 end
10 8
11 css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').remove9 css('.projectTitle').each do |node|
10 node.name = 'h1'
11 node.content = 'Relay'
12 end
12 13
13 css('table h1', 'table h2', 'table h3').each do |node|14 css('pre').remove
14 table = node
15 table = table.parent until table.name == 'table'
16 table.replace(node)
17 end
18 15
19 css('a.anchor', 'a.hashref').each do |node|
20 node.parent['id'] ||= node['name'] || node['id']
21 end16 end
22 17
23 css('.highlight').each do |node|18 css('.docLastUpdate').remove
24 node.name = 'pre'
25 node.css('.gutter').remove
26 node['data-language'] = node.at_css('[data-lang]').try(:[], 'data-lang') || 'js'
27 node.content = node.content.strip
28 end
29 19
30 css('table.highlighttable').each do |node|20 css('.docs-prevnext').remove
31 node.replace(node.at_css('pre.highlight'))
32 end
33 21
34 css('.prism').each do |node|22 css('.edit-page-link').remove
35 node.name = 'pre'
36 node['data-language'] = node['class'][/(?<=language\-)(\w+)/]
37 node.content = node.content
38 end
39 23
40 css('blockquote > p:first-child').each do |node|24 css('h2, h3').each do |node|
41 node.remove if node.content.strip == 'Note:'25 node.css('a').remove
26 node['id'] = node.content.gsub(/\s/, '-').downcase
42 end27 end
43 28
44 css('h3#props', 'h3#methods').each { |node| node.name = 'h2' }29 css('.onPageNav').remove
45 css('h4.propTitle').each { |node| node.name = 'h3' }
46 30
47 css('> div > div', '> div', 'div > span', '.props', '.prop').each do |node|31 css('#docsNav').remove
48 node.before(node.children).remove
49 end
50 32
51 css('a pre', 'h3 .propType').each do |node|33 css('.fixedHeaderContainer').remove
52 node.name = 'code'34
53 end35 css('footer').remove
54 36
55 css('a[target]').each do |node|37 # syntax highlight
56 node.remove_attribute('target')38 css('pre').each do |node|
39 node['data-language'] = 'javascript'
40 node.add_class('highlight')
57 end41 end
58 42
59 doc43 doc
lib/docs/filters/relay/entries.rb+32−22
@@ -1,43 +1,53 @@
1module Docs1module Docs
2 class Relay2 class Relay
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4
4 def get_name5 def get_name
5 at_css('h1').children.select(&:text?).map(&:content).join.strip6 if slug == 'index'
7 return 'Relay'
8 end
9
10 at_css('h1').content
6 end11 end
7 12
8 def get_type13 def get_type
9 link = at_css('.nav-docs-section .active, .toc .active')14 if slug == 'index'
10 section = link.ancestors('.nav-docs-section, section').first15 return 'Relay'
11 type = section.at_css('h3').content.strip16 end
12 type17
18 at_css('h1').content
13 end19 end
14 20
15 def additional_entries21 def additional_entries
16 entries = []22 entries = []
17 23
18 css('.inner-content h3 code, .inner-content h4 code').each do |node|24 if slug == 'index'
19 name = node.content25 return entries
20 name.remove! %r{[#\(\)]}
21 name.remove! %r{\w+\:}
22 name.strip!
23 id = name.parameterize
24 node.parent['id'] = id
25 entries << [name, id, 'Reference']
26 end26 end
27 27
28 css('.apiIndex a pre').each do |node|28 ## avoid adding non-desired entries removing tags
29 next unless node.parent['href'].start_with?('#')29 # remove header which contains a <h2> tag
30 id = node.parent['href'].remove('#')30 css('.fixedHeaderContainer').remove
31 name = node.content.strip31
32 sep = name.start_with?('static') ? '.' : '#'32 # remove table of content whose title is an <h2> tag
33 name.remove! %r{(abstract|static) }33 css('.toc').remove
34 name.sub! %r{\(.*\)}, '()'34 ##
35 name.prepend(self.name + sep)35
36 entries << [name, id]36 css('h2, h3').each do |node|
37 next if node.content.include?('Argument')
38 entry_name = node.content
39
40 if entry_name.include?('(')
41 entry_name = entry_name.match(/.*\(/)[0] + ')'
42 end
43
44 entry_id = node.content.gsub(/\s/, '-').downcase
45 entries << [entry_name, entry_id]
37 end46 end
38 47
39 entries48 entries
40 end49 end
50
41 end51 end
42 end52 end
43end53end
lib/docs/scrapers/relay.rb+20−9
@@ -1,27 +1,38 @@
1module Docs1module Docs
2 class Relay < UrlScraper2 class Relay < UrlScraper
3 self.type = 'simple'3 self.type = 'simple'
4 self.release = '1.4.1'4 self.release = '10.1.0'
5 self.base_url = 'https://facebook.github.io/relay/docs/'5 self.base_url = 'https://relay.dev'
6 self.root_path = 'getting-started.html'6 self.root_path = 'index.html'
7 self.links = {7 self.links = {
8 home: 'https://facebook.github.io/relay/',8 home: 'https://relay.dev/',
9 code: 'https://github.com/facebook/relay'9 code: 'https://github.com/facebook/relay'
10 }10 }
11 11
12 html_filters.push 'relay/entries', 'relay/clean_html'12 html_filters.push 'relay/entries', 'relay/clean_html'
13 13
14 options[:container] = '.documentationContent'14 options[:only] = [
15 options[:skip] = %w(videos.html graphql-further-reading.html)15 '/docs/en/graphql-in-relay',
16 '/docs/en//relay-environment',
17 '/docs/en/network-layer',
18 '/docs/en/query-renderer',
19 '/docs/en/fragment-container',
20 '/docs/en/refetch-container',
21 '/docs/en/pagination-container',
22 '/docs/en/mutations',
23 '/docs/en/subscriptions',
24 '/docs/en/relay-store',
25 '/docs/en/fetch-query'
26 ]
16 27
17 options[:attribution] = <<-HTML28 options[:attribution] = <<-HTML
18 &copy; 2013&ndash;present Facebook Inc.<br>29 &copy; 2020&ndash;present Facebook Inc.<br>
19 Licensed under the BSD License.30 Licensed under the BSD License.
20 HTML31 HTML
21 32
22 def get_latest_version(opts)33 def get_latest_version(opts)
23 doc = fetch_doc('http://facebook.github.io/relay/en/', opts)34 get_latest_github_release('facebook', 'relay', opts)
24 doc.at_css('header > a > h3').content[1..-1]
25 end35 end
36
26 end37 end
27end38end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t