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'
], [
'Meteor',
'2011-2015 Meteor Development Group',
'2011-2016 Meteor Development Group',
'MIT',
'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')
return
app.views.MeteorPage =
app.views.TypescriptPage =
app.views.SimplePage

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

@ -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('<br>', "\n")
node['data-language'] = node['class'].split.last
node.name = 'pre'
end
end
end
end

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

@ -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
&copy; 2011&ndash;2015 Meteor Development Group<br>
&copy; 2011&ndash;2016 Meteor Development Group<br>
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

Loading…
Cancel
Save