Update Meteor documentation (1.3.0) and add new URL stubbing mechanism

pull/382/head
Thibaut Courouble 9 years ago
parent 71bbf4994b
commit 5f7005729c

@ -276,7 +276,7 @@ credits = [
'https://daringfireball.net/projects/markdown/license' 'https://daringfireball.net/projects/markdown/license'
], [ ], [
'Meteor', 'Meteor',
'2011-2015 Meteor Development Group', '2011-2016 Meteor Development Group',
'MIT', 'MIT',
'https://raw.githubusercontent.com/meteor/meteor/master/LICENSE.txt' 'https://raw.githubusercontent.com/meteor/meteor/master/LICENSE.txt'
], [ ], [

@ -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

@ -6,5 +6,6 @@ class app.views.SimplePage extends app.views.BasePage
@highlightCode el, el.getAttribute('data-language') @highlightCode el, el.getAttribute('data-language')
return return
app.views.MeteorPage =
app.views.TypescriptPage = app.views.TypescriptPage =
app.views.SimplePage app.views.SimplePage

@ -3,7 +3,7 @@ require 'set'
module Docs module Docs
class Scraper < Doc class Scraper < Doc
class << self 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) def inherited(subclass)
super super
@ -19,17 +19,24 @@ module Docs
subclass.options = options.deep_dup subclass.options = options.deep_dup
subclass.html_filters = html_filters.inheritable_copy subclass.html_filters = html_filters.inheritable_copy
subclass.text_filters = text_filters.inheritable_copy subclass.text_filters = text_filters.inheritable_copy
subclass.stubs = stubs.dup
end end
def filters def filters
html_filters.to_a + text_filters.to_a html_filters.to_a + text_filters.to_a
end end
def stub(path, &block)
@stubs[path] = block
@stubs
end
end end
include Instrumentable include Instrumentable
self.initial_paths = [] self.initial_paths = []
self.options = {} self.options = {}
self.stubs = {}
self.html_filters = FilterStack.new self.html_filters = FilterStack.new
self.text_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' html_filters.push 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths'
text_filters.push 'inner_html', 'clean_text', 'attribution' 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) def build_page(path)
response = request_one url_for(path) response = request_one url_for(path)
result = handle_response(response) result = handle_response(response)

@ -2,24 +2,39 @@ module Docs
class Meteor class Meteor
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
root_page? ? root : other
doc
end
def root
@doc = at_css('#introduction').parent @doc = at_css('#introduction').parent
css('.github-ribbon').remove css('.github-ribbon', '#introduction').remove
css('.selflink', 'b > em').each do |node| css('.selflink', 'b > em').each do |node|
node.before(node.children).remove node.before(node.children).remove
end end
css('pre').each do |node| 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 node.content = node.content
end end
css('a.src-code').each do |node| css('a.src-code').each do |node|
node.content = 'Source' node.content = 'Source'
end 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('<br>', "\n")
node['data-language'] = node['class'].split.last
node.name = 'pre'
end
end end
end end
end end

@ -1,7 +1,20 @@
module Docs module Docs
class Meteor class Meteor
class EntriesFilter < Docs::EntriesFilter 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 def additional_entries
return [] unless root_page?
type = nil type = nil
at_css('.full-api-toc').element_children.each_with_object [] do |node, entries| at_css('.full-api-toc').element_children.each_with_object [] do |node, entries|
@ -11,14 +24,8 @@ module Docs
target = link['href'].remove('#/full/') target = link['href'].remove('#/full/')
case node.name case node.name
when 'h1' when 'h1', 'h2'
type = node.content.strip type = node.content.strip
when 'h2'
if type == 'Concepts'
entries << [node.content, target, type]
else
type = node.content.strip
end
when 'h3', 'h4' when 'h3', 'h4'
entries << [node.content, target, type] entries << [node.content, target, type]
end end

@ -1,33 +1,36 @@
module Docs module Docs
class Meteor < UrlScraper class Meteor < UrlScraper
include StubRootPage
self.type = 'meteor' self.type = 'meteor'
self.release = '1.2.0' self.release = '1.3.0'
self.base_url = 'http://docs.meteor.com' self.base_url = 'http://guide.meteor.com/v1.3/'
self.root_path = '/#/full/' self.initial_paths = %w(guide)
self.links = { self.links = {
home: 'https://www.meteor.com/', home: 'https://www.meteor.com/',
code: 'https://github.com/meteor/meteor/' 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] = ->(filter) { filter.root_page? }
options[:skip_links] = true
options[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; 2011&ndash;2015 Meteor Development Group<br> &copy; 2011&ndash;2016 Meteor Development Group<br>
Licensed under the MIT License. Licensed under the MIT License.
HTML HTML
private stub '' do
require 'capybara/dsl'
def root_page_body
require 'capybara'
Capybara.current_driver = :selenium 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'] Capybara.find('.body')['innerHTML']
end end
stub 'guide' do
request_one(url_for('index.html')).body
end
options[:replace_paths] = { 'index.html' => 'guide' }
end end
end end

Loading…
Cancel
Save