From 5f7005729cc161630e9dc282a069dd3ab6dd5aea Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 3 Apr 2016 11:16:46 -0400 Subject: [PATCH] Update Meteor documentation (1.3.0) and add new URL stubbing mechanism --- .../templates/pages/about_tmpl.coffee | 2 +- assets/javascripts/views/pages/meteor.coffee | 7 ----- assets/javascripts/views/pages/simple.coffee | 1 + lib/docs/core/scraper.rb | 26 +++++++++++++++- lib/docs/filters/meteor/clean_html.rb | 21 +++++++++++-- lib/docs/filters/meteor/entries.rb | 21 ++++++++----- lib/docs/scrapers/meteor.rb | 31 ++++++++++--------- 7 files changed, 76 insertions(+), 33 deletions(-) delete mode 100644 assets/javascripts/views/pages/meteor.coffee diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 4d75d775..35dfb034 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -276,7 +276,7 @@ credits = [ 'https://daringfireball.net/projects/markdown/license' ], [ 'Meteor', - '2011-2015 Meteor Development Group', + '2011-2016 Meteor Development Group', 'MIT', 'https://raw.githubusercontent.com/meteor/meteor/master/LICENSE.txt' ], [ diff --git a/assets/javascripts/views/pages/meteor.coffee b/assets/javascripts/views/pages/meteor.coffee deleted file mode 100644 index bb41f6a1..00000000 --- a/assets/javascripts/views/pages/meteor.coffee +++ /dev/null @@ -1,7 +0,0 @@ -#= require views/pages/base - -class app.views.MeteorPage extends app.views.BasePage - prepare: -> - @highlightCode @findAll('pre.js, pre.javascript'), 'javascript' - @highlightCode @findAll('pre.html'), 'markup' - return diff --git a/assets/javascripts/views/pages/simple.coffee b/assets/javascripts/views/pages/simple.coffee index 058a2386..579d3cdf 100644 --- a/assets/javascripts/views/pages/simple.coffee +++ b/assets/javascripts/views/pages/simple.coffee @@ -6,5 +6,6 @@ class app.views.SimplePage extends app.views.BasePage @highlightCode el, el.getAttribute('data-language') return +app.views.MeteorPage = app.views.TypescriptPage = app.views.SimplePage diff --git a/lib/docs/core/scraper.rb b/lib/docs/core/scraper.rb index 9f973c8a..1d78a232 100644 --- a/lib/docs/core/scraper.rb +++ b/lib/docs/core/scraper.rb @@ -3,7 +3,7 @@ require 'set' module Docs class Scraper < Doc class << self - attr_accessor :base_url, :root_path, :initial_paths, :options, :html_filters, :text_filters + attr_accessor :base_url, :root_path, :initial_paths, :options, :html_filters, :text_filters, :stubs def inherited(subclass) super @@ -19,17 +19,24 @@ module Docs subclass.options = options.deep_dup subclass.html_filters = html_filters.inheritable_copy subclass.text_filters = text_filters.inheritable_copy + subclass.stubs = stubs.dup end def filters html_filters.to_a + text_filters.to_a end + + def stub(path, &block) + @stubs[path] = block + @stubs + end end include Instrumentable self.initial_paths = [] self.options = {} + self.stubs = {} self.html_filters = FilterStack.new self.text_filters = FilterStack.new @@ -37,6 +44,23 @@ module Docs html_filters.push 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths' text_filters.push 'inner_html', 'clean_text', 'attribution' + def initialize + super + initialize_stubs + end + + def initialize_stubs + self.class.stubs.each do |path, block| + Typhoeus.stub(url_for(path)).and_return do + Typhoeus::Response.new \ + effective_url: url_for(path), + code: 200, + headers: { 'Content-Type' => 'text/html' }, + body: self.instance_exec(&block) + end + end + end + def build_page(path) response = request_one url_for(path) result = handle_response(response) diff --git a/lib/docs/filters/meteor/clean_html.rb b/lib/docs/filters/meteor/clean_html.rb index e69999a1..1a62690e 100644 --- a/lib/docs/filters/meteor/clean_html.rb +++ b/lib/docs/filters/meteor/clean_html.rb @@ -2,24 +2,39 @@ module Docs class Meteor class CleanHtmlFilter < Filter def call + root_page? ? root : other + doc + end + + def root @doc = at_css('#introduction').parent - css('.github-ribbon').remove + css('.github-ribbon', '#introduction').remove css('.selflink', 'b > em').each do |node| node.before(node.children).remove end css('pre').each do |node| - node['class'] = node.at_css('code')['class'] + node['data-language'] = node.at_css('code')['class'].include?('html') ? 'html' : 'js' node.content = node.content end css('a.src-code').each do |node| node.content = 'Source' end + end - doc + def other + @doc = at_css('#content') + + css('.edit-discuss-links', '.bottom-nav', '.edit-link').remove + + css('figure.highlight').each do |node| + node.inner_html = node.at_css('.code pre').inner_html.gsub('
', "\n") + node['data-language'] = node['class'].split.last + node.name = 'pre' + end end end end diff --git a/lib/docs/filters/meteor/entries.rb b/lib/docs/filters/meteor/entries.rb index 8fbb8070..0cf7c345 100644 --- a/lib/docs/filters/meteor/entries.rb +++ b/lib/docs/filters/meteor/entries.rb @@ -1,7 +1,20 @@ module Docs class Meteor class EntriesFilter < Docs::EntriesFilter + def get_name + at_css('#content > h1').content + end + + def get_type + if (node = at_css('#sidebar .current')) && (node = node.ancestors('.menu-root').first.previous_element) + "Guide: #{node.content}" + else + 'Guide' + end + end + def additional_entries + return [] unless root_page? type = nil at_css('.full-api-toc').element_children.each_with_object [] do |node, entries| @@ -11,14 +24,8 @@ module Docs target = link['href'].remove('#/full/') case node.name - when 'h1' + when 'h1', 'h2' type = node.content.strip - when 'h2' - if type == 'Concepts' - entries << [node.content, target, type] - else - type = node.content.strip - end when 'h3', 'h4' entries << [node.content, target, type] end diff --git a/lib/docs/scrapers/meteor.rb b/lib/docs/scrapers/meteor.rb index 24276f75..c502ebe9 100644 --- a/lib/docs/scrapers/meteor.rb +++ b/lib/docs/scrapers/meteor.rb @@ -1,33 +1,36 @@ module Docs class Meteor < UrlScraper - include StubRootPage - self.type = 'meteor' - self.release = '1.2.0' - self.base_url = 'http://docs.meteor.com' - self.root_path = '/#/full/' + self.release = '1.3.0' + self.base_url = 'http://guide.meteor.com/v1.3/' + self.initial_paths = %w(guide) self.links = { home: 'https://www.meteor.com/', code: 'https://github.com/meteor/meteor/' } - html_filters.push 'meteor/entries', 'meteor/clean_html', 'title' + html_filters.push 'meteor/entries', 'meteor/clean_html' - options[:title] = 'Meteor' - options[:skip_links] = true + options[:skip_links] = ->(filter) { filter.root_page? } options[:attribution] = <<-HTML - © 2011–2015 Meteor Development Group
+ © 2011–2016 Meteor Development Group
Licensed under the MIT License. HTML - private - - def root_page_body - require 'capybara' + stub '' do + require 'capybara/dsl' Capybara.current_driver = :selenium - Capybara.visit(root_url.to_s) + Capybara.run_server = false + Capybara.app_host = 'https://docs.meteor.com' + Capybara.visit('/#/full/') Capybara.find('.body')['innerHTML'] end + + stub 'guide' do + request_one(url_for('index.html')).body + end + + options[:replace_paths] = { 'index.html' => 'guide' } end end