diff --git a/assets/stylesheets/pages/_ember.scss b/assets/stylesheets/pages/_ember.scss index 40771e6e..636b56b6 100644 --- a/assets/stylesheets/pages/_ember.scss +++ b/assets/stylesheets/pages/_ember.scss @@ -1,22 +1,20 @@ ._ember { @extend %simple; - blockquote.class-info { @extend %note-blue; } - blockquote.class-info > p { margin: 0; } - .pre-title { @extend %pre-heading; } - h2 > .flag, h2 > .type { - margin-left: .5em; + h3 > .access { + float: right; color: $textColorLight; font-weight: normal; } - h2 > .type { float: right; } - - .meta { color: $textColorLight; } + h3 > .args, + h3 > .return-type { + font-weight: normal; + } - dl { margin: 0 1em; } - dt + dt, dd + dt { margin-top: .5em; } - dt > code { @extend %label; } + p.github-link { + color: $textColorLight; + } } diff --git a/lib/docs/filters/ember/clean_html.rb b/lib/docs/filters/ember/clean_html.rb index 5a10e613..4f210ce2 100644 --- a/lib/docs/filters/ember/clean_html.rb +++ b/lib/docs/filters/ember/clean_html.rb @@ -13,79 +13,69 @@ module Docs node['data-language'] = node['data-language'].sub(/(hbs|handlebars)/, 'html') end - if base_url.path.start_with?('/api') - root_page? ? root : api - else - guide - end + base_url.path.start_with?('/api') ? api : guide doc end - def root - css('#back-to-top').remove - - # Remove "Projects" and "Tag" links - css('.level-1:nth-child(1)', '.level-1:nth-child(2)').remove - - # Turn section links (e.g. Modules) into headings - css('.level-1 > a').each do |node| - node.name = 'h2' - node.remove_attribute 'href' + def api + css('h1 .access').each do |node| + node.replace(" (#{node.content})") end - # Remove root-level list - css('.level-1').each do |node| - node.before(node.elements).remove + css('*[data-anchor]').each do |node| + node['id'] = node['data-anchor'] + node.remove_attribute('data-anchor') end - css('ol').each do |node| - node.name = 'ul' + css('> h3[id]').each do |node| + node.name = 'h2' end - end - def api - css('#api-options', '.toc-anchor', '.inherited').remove - - # Remove tabs and "Index" - css('.tabs').each do |node| - panes = node.css '#methods', '#events', '#properties' - panes.remove_attr 'style' - node.before(panes).remove + if subpath.end_with?('/methods') || subpath.end_with?('/properties') || subpath.end_with?('/events') + css('.attributes ~ *').each do |node| + break if node['class'] == 'tabbed-layout' + node.remove + end end - css('.method', '.property', '.event').remove_attr('id') + css('.attributes').each do |node| + html = node.inner_html + html.gsub! %r{(.+?)}, '\1' + html.gsub! %r{(.+?)}, '\1' + html.gsub! %r{
(.+?)
}, '\1' + node.replace("#{html}
") + end - css('h3[data-id]').each do |node| - heading = Nokogiri::XML::Node.new 'h2', doc - heading['id'] = node['data-id'] - node.before(heading).remove - heading.content = node.content - heading.add_child(heading.next_element) while heading.next_element.name == 'span' + css('div.attribute').each do |node| + node.name = 'p' end - css('> .class-info').each do |node| - node.name = 'blockquote' + css('.tabbed-layout').each do |node| + node.before(node.at_css('.api__index__content', '.api-index-filter')).remove end - css('div.meta').each do |node| - node.name = 'p' + css('div.ember-view', 'dl > div').each do |node| + node.before(node.children).remove end - css('span.type').each do |node| - node.name = 'code' + css('section > h3').each do |node| + node.name = 'h4' if node.previous_element end - css('.pane', '.item-entry').each do |node| + css('section').each do |node| node.before(node.children).remove end + + css('ul', 'h3', 'h4', 'a').remove_attr('class') + css('a[id]').remove_attr('id') end def guide @doc = at_css('article') if root_page? - at_css('h1').remove + at_css('h1').content = 'Ember.js' end css('.previous-guide', '.next-guide').remove diff --git a/lib/docs/filters/ember/entries.rb b/lib/docs/filters/ember/entries.rb index 301618d0..39125adc 100644 --- a/lib/docs/filters/ember/entries.rb +++ b/lib/docs/filters/ember/entries.rb @@ -3,10 +3,13 @@ module Docs class EntriesFilter < Docs::EntriesFilter def get_name if base_url.path.start_with?('/api') - name = at_css('.api-header').content.split.first + name = at_css('h1').child.content.strip # Remove "Ember." prefix if the next character is uppercase name.sub! %r{\AEmber\.([A-Z])(?!EATURES)}, '\1' - name == 'Handlebars.helpers' ? 'Handlebars Helpers' : name + name << ' (methods)' if subpath.end_with?('/methods') + name << ' (properties)' if subpath.end_with?('/properties') + name << ' (events)' if subpath.end_with?('/events') + name else name = at_css('article h1').content.remove('Edit Page').strip name = at_css('li.toc-level-0.selected > a').content if name == 'Introduction' @@ -16,13 +19,14 @@ module Docs def get_type if base_url.path.start_with?('/api') - if at_css('.api-header').content.include?('Module') + name = self.name.remove(/ \(.*/) + if name =~ /\A[a-z\-]+\z/ 'Modules' - elsif name.start_with? 'DS' + elsif name.start_with?('DS') 'Data' - elsif name.start_with? 'RSVP' + elsif name.start_with?('RSVP') 'RSVP' - elsif name.start_with? 'Test' + elsif name.start_with?('Test') 'Test' elsif name.start_with?('Ember') name.split('.')[0..1].join('.') @@ -41,29 +45,21 @@ module Docs def additional_entries return [] unless base_url.path.start_with?('/api') - css('.item-entry:not(.inherited)').map do |node| - heading = node.at_css('h3[data-id]') - name = heading.content.strip - - if self.name == 'Handlebars Helpers' - name << ' (handlebars helper)' - next [name, heading['data-id']] - end + css('section').each_with_object [] do |node, entries| + next unless heading = node.at_css('h3[data-anchor]') + next if node.at_css('.github-link').content.include?('Inherited') + name = heading.at_css('span').content.strip # Give their own type to "Ember.platform", "Ember.run", etc. if self.type != 'Data' && name.include?('.') - type = "#{self.name}.#{name.split('.').first}" + type = "#{self.name.remove(/ \(.*/)}.#{name.split('.').first}" end - # "." = class method, "#" = instance method - separator = '#' - separator = '.' if self.name == 'Ember' || self.name.split('.').last =~ /\A[a-z]/ || node.at_css('.static') - name.prepend self.name + separator - - name << '()' if node['class'].include? 'method' - name << ' event' if node['class'].include? 'event' + name.prepend "#{self.name.remove(/ \(.*/)}." + name << '()' if node['class'].include?('method') + name << ' (event)' if node['class'].include?('event') - [name, heading['data-id'], type] + entries << [name, heading['data-anchor'], type] end end end diff --git a/lib/docs/scrapers/ember.rb b/lib/docs/scrapers/ember.rb index 0e0a9e5d..ae57079e 100644 --- a/lib/docs/scrapers/ember.rb +++ b/lib/docs/scrapers/ember.rb @@ -5,35 +5,56 @@ module Docs self.name = 'Ember.js' self.slug = 'ember' self.type = 'ember' - self.release = '2.13.0' - self.base_urls = ['https://emberjs.com/api/', 'https://guides.emberjs.com/v2.13.0/'] + self.release = '2.14.0' + self.base_urls = [ + 'https://guides.emberjs.com/v2.14.0/', + 'https://emberjs.com/api/ember/2.14/', + 'https://emberjs.com/api/ember-data/2.14/' + ] self.links = { home: 'https://emberjs.com/', code: 'https://github.com/emberjs/ember.js' } - html_filters.push 'ember/entries', 'ember/clean_html', 'title' + html_filters.push 'ember/entries', 'ember/clean_html' options[:trailing_slash] = false - options[:title] = false - options[:root_title] = 'Ember.js' - options[:container] = ->(filter) do if filter.base_url.path.start_with?('/api') - filter.root_page? ? '#toc-list' : '#content' + 'main article' else 'main' end end - # Duplicates - options[:skip] = %w(classes/String.html data/classes/DS.html) - options[:skip_patterns] = [/\._/, /contributing/] + options[:fix_urls] = ->(url) do + url.sub! '?anchor=', '#' + url.sub! %r{/methods/[^?#/]+}, '/methods' + url.sub! %r{/properties/[^?#/]+}, '/properties' + url.sub! %r{/events/[^?#/]+}, '/events' + url + end + + options[:skip_patterns] = [ + /\._/, + /contributing/, + /classes\/String/, + /namespaces\/Ember/, + /namespaces\/DS/ + ] options[:attribution] = <<-HTML © 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License. HTML + + def initial_urls + %w( + https://guides.emberjs.com/v2.14.0/ + https://emberjs.com/api/ember/2.14/classes/Ember + https://emberjs.com/api/ember-data/2.14/classes/DS + ) + end end end