Update and version Meteor documentation

pull/469/head
Thibaut Courouble 9 years ago
parent 30900c3562
commit b279f84a4c

@ -1,15 +1,18 @@
._meteor { ._meteor {
@extend %simple; @extend %simple;
.note, .warning { @extend %note; } .note, .warning, .subtitle-page { @extend %note; }
.subtitle-page { @extend %note-blue; }
.warning { @extend %note-red; } .warning { @extend %note-red; }
dl.args { margin-left: 1rem; } dl.args { margin-left: 1rem; }
dt > code { @extend %label; }
.api-heading { overflow: hidden; }
.api-heading > code { font-weight: bold; }
.locus, .src-code { float: right; } .locus, .src-code { float: right; }
.locus, .type, .src-code { .locus, .type, .src-code { margin-left: .5em; }
margin-left: .5em; h2 .subtext-api { margin-top: .25rem; }
font-size: .9em; .locus, .subtext-api, .subtext-api > code { font-size: .75rem; }
}
.locus, .type { color: $textColorLight; } .locus, .type { color: $textColorLight; }
} }

@ -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, :stubs attr_accessor :base_url, :root_path, :initial_paths, :initial_urls, :options, :html_filters, :text_filters, :stubs
def inherited(subclass) def inherited(subclass)
super super
@ -16,6 +16,7 @@ module Docs
subclass.base_url = base_url subclass.base_url = base_url
subclass.root_path = root_path subclass.root_path = root_path
subclass.initial_paths = initial_paths.dup subclass.initial_paths = initial_paths.dup
subclass.initial_urls = initial_urls.dup
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
@ -35,6 +36,7 @@ module Docs
include Instrumentable include Instrumentable
self.initial_paths = [] self.initial_paths = []
self.initial_urls = []
self.options = {} self.options = {}
self.stubs = {} self.stubs = {}
@ -103,7 +105,7 @@ module Docs
end end
def initial_urls def initial_urls
@initial_urls ||= [root_url.to_s].concat(initial_paths.map(&method(:url_for))).freeze @initial_urls ||= [root_url.to_s].concat(self.class.initial_urls).concat(initial_paths.map(&method(:url_for))).freeze
end end
def pipeline def pipeline

@ -33,7 +33,11 @@ module Docs
raise "Error status code (#{response.code}): #{response.url}" raise "Error status code (#{response.code}): #{response.url}"
end end
response.success? && response.html? && base_url.contains?(response.effective_url) response.success? && response.html? && process_url?(response.effective_url)
end
def process_url?(url)
base_url.contains?(url)
end end
def load_capybara_selenium def load_capybara_selenium

@ -2,44 +2,45 @@ module Docs
class Meteor class Meteor
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
root_page? ? root : other @doc = at_css('.content-wrapper')
css('pre span').each do |node| css('.page-actions', '.anchor').remove
node.before(node.children).remove
end
doc
end
def root css('.header-content', '.document-formatting', 'h2 > a', '.api', '.api-body', 'div.desc').each do |node|
@doc = at_css('#introduction').parent
css('.github-ribbon', '#introduction').remove
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('.anchor-offset').each do |node|
node['data-language'] = node.at_css('code')['class'].include?('html') ? 'html' : 'js' node.parent['id'] = node['id']
node.content = node.content node.remove
end end
css('a.src-code').each do |node| css('.api-heading').each do |node|
node.content = 'Source' heading = node.at_css('h2, h3')
name = heading.name
node['id'] = heading['id']
heading.replace "<code>#{heading.content.strip}</code>"
node.name = name
end end
end
def other css('div.code', 'span.code', '.args .name').each do |node|
@doc = at_css('#content') node.name = 'code'
node.remove_attribute('class')
css('.edit-discuss-links', '.bottom-nav', '.edit-link').remove end
css('figure.highlight').each do |node| css('figure.highlight').each do |node|
node.inner_html = node.at_css('.code pre').inner_html.gsub('<br>', "\n") node.inner_html = node.at_css('.code pre').inner_html.gsub('</div><div', "</div>\n<div").gsub('<br>', "\n")
node.content = node.content
node['data-language'] = node['class'].split.last node['data-language'] = node['class'].split.last
node.name = 'pre' node.name = 'pre'
end end
css('pre.prettyprint').each do |node|
node['data-language'] = node['class'].include?('html') ? 'html' : 'js'
node.content = node.content
end
doc
end end
end end
end end

@ -2,32 +2,31 @@ module Docs
class Meteor class Meteor
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
at_css('#content > h1').content at_css('.item-toc.current').content
end end
def get_type def get_type
if (node = at_css('#sidebar .current')) && (node = node.ancestors('.menu-root').first.previous_element) if subpath.start_with?('api')
"Guide: #{node.content}" name
else else
'Guide' type = at_css('.item-toc.current').ancestors('li').first.at_css('.heading-toc').try(:content) || 'Guide'
type.prepend 'Guide: ' if base_url.host == 'guide.meteor.com' && type != 'Guide'
type
end end
end end
def additional_entries def additional_entries
return [] unless root_page? if slug == 'commandline'
type = nil css('h2[id]').map do |node|
[node.content, node['id']]
at_css('.full-api-toc').element_children.each_with_object [] do |node, entries| end
link = node.at_css('a') else
next unless link css('.title-api[id]').map do |node|
name = node.content.strip
target = link['href'].remove('#/full/') name.sub! %r{\(.+\)}, '()'
name.remove! 'new '
case node.name name = '{{> Template.dynamic }}' if name.include?('Template.dynamic')
when 'h1', 'h2' [name, node['id']]
type = node.content.strip
when 'h3', 'h4'
entries << [node.content, target, type]
end end
end end
end end

@ -1,9 +1,11 @@
module Docs module Docs
class Meteor < UrlScraper class Meteor < UrlScraper
class << self
attr_accessor :guide_url
end
self.type = 'meteor' self.type = 'meteor'
self.release = '1.3.2' self.root_path = 'index.html'
self.base_url = 'https://guide.meteor.com/v1.3/'
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/'
@ -11,26 +13,52 @@ module Docs
html_filters.push 'meteor/entries', 'meteor/clean_html' html_filters.push 'meteor/entries', 'meteor/clean_html'
options[:skip_links] = ->(filter) { filter.root_page? } options[:skip_patterns] = [/\Av\d/]
options[:skip] = %w(
CONTRIBUTING.html
CHANGELOG.html
using-packages.html
writing-packages.html
)
options[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; 2011&ndash;2016 Meteor Development Group<br> &copy; 2011&ndash;2016 Meteor Development Group<br>
Licensed under the MIT License. Licensed under the MIT License.
HTML HTML
stub '' do version '1.4' do
require 'capybara/dsl' self.release = '1.4.0'
Capybara.current_driver = :selenium self.base_url = 'https://docs.meteor.com/'
Capybara.run_server = false self.guide_url = 'https://guide.meteor.com/'
Capybara.app_host = 'https://docs.meteor.com' self.initial_urls = [guide_url]
Capybara.visit('/#/full/') end
Capybara.find('.body')['innerHTML']
version '1.3' do
self.release = '1.3.5'
self.base_url = "https://docs.meteor.com/v#{self.release}/"
self.guide_url = 'https://guide.meteor.com/v1.3/'
self.initial_urls = [guide_url]
end end
stub 'guide' do def guide_url
request_one(url_for('index.html')).body @guide_url ||= URL.parse(self.class.guide_url)
end end
options[:replace_paths] = { 'index.html' => 'guide' } private
def process_url?(url)
base_url.contains?(url) || guide_url.contains?(url)
end
def process_response(response)
original_host = @base_url.host
original_path = @base_url.path
@base_url.host = response.effective_url.host
@base_url.path = response.effective_url.path[/\A\/v[\d\.]+\//, 0] || '/'
super
ensure
@base_url.host = original_host
@base_url.path = original_path
end
end end
end end

Loading…
Cancel
Save