History

Update and version Meteor documentation

Thibaut Courouble committed 10 years ago

Commit b279f841 parent 30900c36 files · +101 −64Browse files

Showing the changes to lib/docs (5 of 6 files). Show all

Unified · Split

5 files
  1. lib/docs/core/scraper.rb +4 −2
  2. lib/docs/core/scrapers/url_scraper.rb +5 −1
  3. lib/docs/filters/meteor/clean_html.rb +25 −24
  4. lib/docs/filters/meteor/entries.rb +17 −18
  5. lib/docs/scrapers/meteor.rb +42 −14
lib/docs/core/scraper.rb+4−2
@@ -3,7 +3,7 @@ require 'set' · 2 unmodified lines
33 module Docs
44 class Scraper < Doc
55 class << self
6− attr_accessor :base_url, :root_path, :initial_paths, :options, :html_filters, :text_filters, :stubs
6+ attr_accessor :base_url, :root_path, :initial_paths, :initial_urls, :options, :html_filters, :text_filters, :stubs
77
88 def inherited(subclass)
99 super
@@ -16,6 +16,7 @@ module Docs · 6 unmodified lines
1616 subclass.base_url = base_url
1717 subclass.root_path = root_path
1818 subclass.initial_paths = initial_paths.dup
19+ subclass.initial_urls = initial_urls.dup
1920 subclass.options = options.deep_dup
2021 subclass.html_filters = html_filters.inheritable_copy
2122 subclass.text_filters = text_filters.inheritable_copy
@@ -35,6 +36,7 @@ module Docs · 13 unmodified lines
3536 include Instrumentable
3637
3738 self.initial_paths = []
39+ self.initial_urls = []
3840 self.options = {}
3941 self.stubs = {}
4042
@@ -103,7 +105,7 @@ module Docs · 62 unmodified lines
103105 end
104106
105107 def initial_urls
106− @initial_urls ||= [root_url.to_s].concat(initial_paths.map(&method(:url_for))).freeze
108+ @initial_urls ||= [root_url.to_s].concat(self.class.initial_urls).concat(initial_paths.map(&method(:url_for))).freeze
107109 end
108110
109111 def pipeline
lib/docs/core/scrapers/url_scraper.rb+5−1
@@ -33,7 +33,11 @@ module Docs · 32 unmodified lines
3333 raise "Error status code (#{response.code}): #{response.url}"
3434 end
3535
36− response.success? && response.html? && base_url.contains?(response.effective_url)
36+ response.success? && response.html? && process_url?(response.effective_url)
37+ end
38+
39+ def process_url?(url)
40+ base_url.contains?(url)
3741 end
3842
3943 def load_capybara_selenium
lib/docs/filters/meteor/clean_html.rb+25−24
@@ -2,44 +2,45 @@ module Docs · 1 unmodified line
22 class Meteor
33 class CleanHtmlFilter < Filter
44 def call
5− root_page? ? root : other
5+ @doc = at_css('.content-wrapper')
66
7− css('pre span').each do |node|
8− node.before(node.children).remove
9− end
10−
11− doc
12− end
7+ css('.page-actions', '.anchor').remove
138
14− def root
15− @doc = at_css('#introduction').parent
16−
17− css('.github-ribbon', '#introduction').remove
18−
19− css('.selflink', 'b > em').each do |node|
9+ css('.header-content', '.document-formatting', 'h2 > a', '.api', '.api-body', 'div.desc').each do |node|
2010 node.before(node.children).remove
2111 end
2212
23− css('pre').each do |node|
24− node['data-language'] = node.at_css('code')['class'].include?('html') ? 'html' : 'js'
25− node.content = node.content
13+ css('.anchor-offset').each do |node|
14+ node.parent['id'] = node['id']
15+ node.remove
2616 end
2717
28− css('a.src-code').each do |node|
29− node.content = 'Source'
18+ css('.api-heading').each do |node|
19+ heading = node.at_css('h2, h3')
20+ name = heading.name
21+ node['id'] = heading['id']
22+ heading.replace "<code>#{heading.content.strip}</code>"
23+ node.name = name
3024 end
31− end
3225
33− def other
34− @doc = at_css('#content')
35−
36− css('.edit-discuss-links', '.bottom-nav', '.edit-link').remove
26+ css('div.code', 'span.code', '.args .name').each do |node|
27+ node.name = 'code'
28+ node.remove_attribute('class')
29+ end
3730
3831 css('figure.highlight').each do |node|
39− node.inner_html = node.at_css('.code pre').inner_html.gsub('<br>', "\n")
32+ node.inner_html = node.at_css('.code pre').inner_html.gsub('</div><div', "</div>\n<div").gsub('<br>', "\n")
33+ node.content = node.content
4034 node['data-language'] = node['class'].split.last
4135 node.name = 'pre'
4236 end
37+
38+ css('pre.prettyprint').each do |node|
39+ node['data-language'] = node['class'].include?('html') ? 'html' : 'js'
40+ node.content = node.content
41+ end
42+
43+ doc
4344 end
4445 end
4546 end
lib/docs/filters/meteor/entries.rb+17−18
@@ -2,32 +2,31 @@ module Docs · 1 unmodified line
22 class Meteor
33 class EntriesFilter < Docs::EntriesFilter
44 def get_name
5− at_css('#content > h1').content
5+ at_css('.item-toc.current').content
66 end
77
88 def get_type
9− if (node = at_css('#sidebar .current')) && (node = node.ancestors('.menu-root').first.previous_element)
10− "Guide: #{node.content}"
9+ if subpath.start_with?('api')
10+ name
1111 else
12− 'Guide'
12+ type = at_css('.item-toc.current').ancestors('li').first.at_css('.heading-toc').try(:content) || 'Guide'
13+ type.prepend 'Guide: ' if base_url.host == 'guide.meteor.com' && type != 'Guide'
14+ type
1315 end
1416 end
1517
1618 def additional_entries
17− return [] unless root_page?
18− type = nil
19−
20− at_css('.full-api-toc').element_children.each_with_object [] do |node, entries|
21− link = node.at_css('a')
22− next unless link
23−
24− target = link['href'].remove('#/full/')
25−
26− case node.name
27− when 'h1', 'h2'
28− type = node.content.strip
29− when 'h3', 'h4'
30− entries << [node.content, target, type]
19+ if slug == 'commandline'
20+ css('h2[id]').map do |node|
21+ [node.content, node['id']]
22+ end
23+ else
24+ css('.title-api[id]').map do |node|
25+ name = node.content.strip
26+ name.sub! %r{\(.+\)}, '()'
27+ name.remove! 'new '
28+ name = '{{> Template.dynamic }}' if name.include?('Template.dynamic')
29+ [name, node['id']]
3130 end
3231 end
3332 end
lib/docs/scrapers/meteor.rb+42−14
@@ -1,9 +1,11 @@
11 module Docs
22 class Meteor < UrlScraper
3+ class << self
4+ attr_accessor :guide_url
5+ end
6+
37 self.type = 'meteor'
4− self.release = '1.3.2'
5− self.base_url = 'https://guide.meteor.com/v1.3/'
6− self.initial_paths = %w(guide)
8+ self.root_path = 'index.html'
79 self.links = {
810 home: 'https://www.meteor.com/',
911 code: 'https://github.com/meteor/meteor/'
@@ -11,26 +13,52 @@ module Docs · 1 unmodified line
1113
1214 html_filters.push 'meteor/entries', 'meteor/clean_html'
1315
14− options[:skip_links] = ->(filter) { filter.root_page? }
16+ options[:skip_patterns] = [/\Av\d/]
17+ options[:skip] = %w(
18+ CONTRIBUTING.html
19+ CHANGELOG.html
20+ using-packages.html
21+ writing-packages.html
22+ )
1523
1624 options[:attribution] = <<-HTML
1725 &copy; 2011&ndash;2016 Meteor Development Group<br>
1826 Licensed under the MIT License.
1927 HTML
2028
21− stub '' do
22− require 'capybara/dsl'
23− Capybara.current_driver = :selenium
24− Capybara.run_server = false
25− Capybara.app_host = 'https://docs.meteor.com'
26− Capybara.visit('/#/full/')
27− Capybara.find('.body')['innerHTML']
29+ version '1.4' do
30+ self.release = '1.4.0'
31+ self.base_url = 'https://docs.meteor.com/'
32+ self.guide_url = 'https://guide.meteor.com/'
33+ self.initial_urls = [guide_url]
34+ end
35+
36+ version '1.3' do
37+ self.release = '1.3.5'
38+ self.base_url = "https://docs.meteor.com/v#{self.release}/"
39+ self.guide_url = 'https://guide.meteor.com/v1.3/'
40+ self.initial_urls = [guide_url]
2841 end
2942
30− stub 'guide' do
31− request_one(url_for('index.html')).body
43+ def guide_url
44+ @guide_url ||= URL.parse(self.class.guide_url)
3245 end
3346
34− options[:replace_paths] = { 'index.html' => 'guide' }
47+ private
48+
49+ def process_url?(url)
50+ base_url.contains?(url) || guide_url.contains?(url)
51+ end
52+
53+ def process_response(response)
54+ original_host = @base_url.host
55+ original_path = @base_url.path
56+ @base_url.host = response.effective_url.host
57+ @base_url.path = response.effective_url.path[/\A\/v[\d\.]+\//, 0] || '/'
58+ super
59+ ensure
60+ @base_url.host = original_host
61+ @base_url.path = original_path
62+ end
3563 end
3664 end