History

Merge pull request #1483 from yads/fix-ember-docs

update Ember docs to latest version

Simon Legner committed 5 years ago

Commit eca99702 parents 4c6c270 5c99f2c4 files · +71 −63Browse files

Unified · Split

4 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +1 −1
  2. lib/docs/filters/ember/clean_html.rb +14 −8
  3. lib/docs/filters/ember/entries.rb +26 −34
  4. lib/docs/scrapers/ember.rb +30 −20
assets/javascripts/templates/pages/about_tmpl.coffee+1−1
@@ -273,7 +273,7 @@ credits = [ · 272 unmodified lines
273 'https://www.gnu.org/licenses/gpl-3.0.html'273 'https://www.gnu.org/licenses/gpl-3.0.html'
274 ], [274 ], [
275 'Ember.js',275 'Ember.js',
276 '2017 Yehuda Katz, Tom Dale and Ember.js contributors',276 '2020 Yehuda Katz, Tom Dale and Ember.js contributors',
277 'MIT',277 'MIT',
278 'https://raw.githubusercontent.com/emberjs/ember.js/master/LICENSE'278 'https://raw.githubusercontent.com/emberjs/ember.js/master/LICENSE'
279 ], [279 ], [
lib/docs/filters/ember/clean_html.rb+14−8
@@ -2,8 +2,14 @@ module Docs · 1 unmodified line
2 class Ember2 class Ember
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 css('hr', '.edit-page').remove5 css('hr', '.edit-page', '.heading__link__edit', 'aside', '.old-version-warning').remove
6 6
7 base_url.host.start_with?('api') ? api : guide
8
9 doc
10 end
11
12 def api
7 # Remove code highlighting13 # Remove code highlighting
8 css('.highlight').each do |node|14 css('.highlight').each do |node|
9 node.before(%(<div class="pre-title"><code>#{node.at_css('thead').content.strip}</code></div>)) if node.at_css('thead')15 node.before(%(<div class="pre-title"><code>#{node.at_css('thead').content.strip}</code></div>)) if node.at_css('thead')
@@ -13,12 +19,6 @@ module Docs · 3 unmodified lines
13 node['data-language'] = node['data-language'].sub(/(hbs|handlebars)/, 'html')19 node['data-language'] = node['data-language'].sub(/(hbs|handlebars)/, 'html')
14 end20 end
15 21
16 base_url.path.start_with?('/api') ? api : guide
17
18 doc
19 end
20
21 def api
22 css('h1 .access').each do |node|22 css('h1 .access').each do |node|
23 node.replace(" (#{node.content})")23 node.replace(" (#{node.content})")
24 end24 end
@@ -72,7 +72,13 @@ module Docs · 47 unmodified lines
72 end72 end
73 73
74 def guide74 def guide
75 @doc = at_css('article')75 # Remove code highlighting
76 css('.filename').each do |node|
77 node.content = node.at_css('pre code').content
78 node.name = 'pre'
79 node['data-language'] = node['class'][/(javascript|js|html|hbs|handlebars)/, 1]
80 node['data-language'] = node['data-language'].sub(/(hbs|handlebars)/, 'html')
81 end
76 82
77 if root_page?83 if root_page?
78 at_css('h1').content = 'Ember.js'84 at_css('h1').content = 'Ember.js'
lib/docs/filters/ember/entries.rb+26−34
@@ -2,60 +2,52 @@ module Docs · 1 unmodified line
2 class Ember2 class Ember
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def get_name4 def get_name
5 if base_url.path.start_with?('/api')5 name = at_css('h1').content
6 name = at_css('h1').child.content.strip6 if base_url.host.start_with?('api')
7 # Remove "Ember." prefix if the next character is uppercase7 name.gsub!('Package', '')
8 name.sub! %r{\AEmber\.([A-Z])(?!EATURES)}, '\1'8 name.gsub!('Class', '')
9 name.strip!
9 name << ' (methods)' if subpath.end_with?('/methods')10 name << ' (methods)' if subpath.end_with?('/methods')
10 name << ' (properties)' if subpath.end_with?('/properties')11 name << ' (properties)' if subpath.end_with?('/properties')
11 name << ' (events)' if subpath.end_with?('/events')12 name << ' (events)' if subpath.end_with?('/events')
12 name
13 else
14 name = at_css('article h1').content.remove('Edit Page').strip
15 name = at_css('li.toc-level-0.selected > a').content if name == 'Introduction'
16 name
17 end13 end
14 name
18 end15 end
19 16
20 def get_type17 def get_type
21 if base_url.path.start_with?('/api')18 if base_url.host.start_with?('api')
22 name = self.name.remove(/ \(.*/)19 name = self.name.remove(/ \(.*/)
23 if name =~ /\A[a-z\-]+\z/20 if name == 'Function'
24 'Modules'21 '3. Functions'
25 elsif name.start_with?('DS')22 elsif at_css('h1').content.start_with?('Package')
26 'Data'23 '2. Packages'
27 elsif name.start_with?('RSVP')
28 'RSVP'
29 elsif name.start_with?('Test')
30 'Test'
31 elsif name.start_with?('Ember')
32 name.split('.')[0..1].join('.')
33 else24 else
34 name.split('.').first25 name = name.remove(' (methods)').remove(' (properties)').remove(' (events)')
26 # Reference gets sorted to the top by default, need to have it with other classes so add a zero width space
27 name == 'Reference' ? 'Reference​' : name
35 end28 end
36 else29 else
37 if node = at_css('li.toc-level-0.selected > a')30 '1. Guide'
38 "Guide: #{node.content.strip}"
39 else
40 'Guide'
41 end
42 end31 end
43 end32 end
44 33
34 def include_default_entry?
35 return false if name == 'Function' # these should be included in the corresponding Package page
36
37 super
38 end
39
45 def additional_entries40 def additional_entries
46 return [] unless base_url.path.start_with?('/api')41 return [] unless base_url.host.start_with?('api')
47 42
48 css('section').each_with_object [] do |node, entries|43 css('section').each_with_object [] do |node, entries|
49 next unless heading = node.at_css('h3[data-anchor]')44 next unless heading = node.at_css('> h3[data-anchor]')
50 next if node.at_css('.github-link').content.include?('Inherited')45
51 name = heading.at_css('span').content.strip46 name = heading.at_css('span').content.strip
52 47
53 # Give their own type to "Ember.platform", "Ember.run", etc.48 next if name.start_with?('_') # exclude private methods/properties
54 if self.type != 'Data' && name.include?('.')
55 type = "#{self.name.remove(/ \(.*/)}.#{name.split('.').first}"
56 end
57 49
58 name.prepend "#{self.name.remove(/ \(.*/)}."50 name.prepend "#{self.name.remove(/ \(.*/)}." unless self.name == 'Function'
59 name << '()' if node['class'].include?('method')51 name << '()' if node['class'].include?('method')
60 name << ' (event)' if node['class'].include?('event')52 name << ' (event)' if node['class'].include?('event')
61 53
lib/docs/scrapers/ember.rb+30−20
@@ -1,3 +1,5 @@
1# frozen_string_literal: true
2
1module Docs3module Docs
2 class Ember < UrlScraper4 class Ember < UrlScraper
3 include MultipleBaseUrls5 include MultipleBaseUrls
@@ -5,12 +7,6 @@ module Docs · 1 unmodified line
5 self.name = 'Ember.js'7 self.name = 'Ember.js'
6 self.slug = 'ember'8 self.slug = 'ember'
7 self.type = 'ember'9 self.type = 'ember'
8 self.release = '2.15.0'
9 self.base_urls = [
10 'https://guides.emberjs.com/v2.15.0/',
11 'https://emberjs.com/api/ember/2.15/',
12 'https://emberjs.com/api/ember-data/2.14/'
13 ]
14 self.links = {10 self.links = {
15 home: 'https://emberjs.com/',11 home: 'https://emberjs.com/',
16 code: 'https://github.com/emberjs/ember.js'12 code: 'https://github.com/emberjs/ember.js'
@@ -21,10 +17,10 @@ module Docs · 4 unmodified lines
21 options[:trailing_slash] = false17 options[:trailing_slash] = false
22 18
23 options[:container] = ->(filter) do19 options[:container] = ->(filter) do
24 if filter.base_url.path.start_with?('/api')20 if filter.base_url.host.start_with?('api')
25 'main article'
26 else
27 'main'21 'main'
22 else
23 'main article'
28 end24 end
29 end25 end
30 26
@@ -39,26 +35,40 @@ module Docs · 8 unmodified lines
39 options[:skip_patterns] = [35 options[:skip_patterns] = [
40 /\._/,36 /\._/,
41 /contributing/,37 /contributing/,
42 /classes\/String/,38 /tutorial/,
43 /namespaces\/Ember/,39 /js-primer/,
44 /namespaces\/DS/40 /in-depth-topics$/,
41 /managing-dependencies$/
45 ]42 ]
46 43
47 options[:attribution] = <<-HTML44 options[:attribution] = <<-HTML
48 &copy; 2017 Yehuda Katz, Tom Dale and Ember.js contributors<br>45 &copy; 2020 Yehuda Katz, Tom Dale and Ember.js contributors<br>
49 Licensed under the MIT License.46 Licensed under the MIT License.
50 HTML47 HTML
51 48
52 def initial_urls49 options[:decode_and_clean_paths] = true # handle paths like @ember/application
53 %w(50
54 https://guides.emberjs.com/v2.15.0/51 version '3' do
55 https://emberjs.com/api/ember/2.15/classes/Ember52 self.release = '3.25.0'
56 https://emberjs.com/api/ember-data/2.14/classes/DS53 self.base_urls = %w[
57 )54 https://guides.emberjs.com/v3.25.0/
55 https://api.emberjs.com/ember/3.25/
56 https://api.emberjs.com/ember-data/3.25/
57 ]
58 end
59
60 version '2' do
61 self.release = '2.18.0'
62 self.base_urls = %w[
63 https://guides.emberjs.com/v2.18.0/
64 https://api.emberjs.com/ember/2.18/
65 https://api.emberjs.com/ember-data/2.18/
66 ]
67 options[:skip_patterns].push(/handlebars-basics$/)
58 end68 end
59 69
60 def get_latest_version(opts)70 def get_latest_version(opts)
61 doc = fetch_doc('https://emberjs.com/api/ember/release', opts)71 doc = fetch_doc('https://api.emberjs.com/ember/release', opts)
62 doc.at_css('.sidebar > .select-container .ember-power-select-selected-item').content.strip72 doc.at_css('.sidebar > .select-container .ember-power-select-selected-item').content.strip
63 end73 end
64 end74 end