History

Finish Vue.js scraper

Thibaut committed 11 years ago

Commit f1cef991 parent eea35dd16 files · +46 −26Browse files

Showing the changes to lib/docs (3 of 16 files). Show all

Unified · Split

3 files
  1. lib/docs/filters/vue/clean_html.rb +8 −1
  2. lib/docs/filters/vue/entries.rb +17 −8
  3. lib/docs/scrapers/vue.rb +10 −5
lib/docs/filters/vue/clean_html.rb+8−1
@@ -2,12 +2,19 @@ module Docs · 1 unmodified line
2 class Vue2 class Vue
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 @doc = at_css('.content')
6
7 at_css('h1').content = 'Vue.js' if root_page?
8
9 css('#demo').remove
10
5 # Remove code highlighting11 # Remove code highlighting
6 css('figure').each do |node|12 css('figure').each do |node|
7 node.name = 'pre'13 node.name = 'pre'
8 node.content = node.at_css('td.code pre').css('.line').map(&:content).join("\n")14 node.content = node.at_css('td.code pre').css('.line').map(&:content).join("\n")
9 end15 end
10 css('.content')16
17 doc
11 end18 end
12 end19 end
13 end20 end
lib/docs/filters/vue/entries.rb+17−8
@@ -1,16 +1,25 @@
1module Docs1module Docs
2 class Vue2 class Vue
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def get_name
5 at_css('h1').content
6 end
7
8 def get_type
9 if slug.start_with?('guide')
10 'Guide'
11 else
12 'API'
13 end
14 end
15
4 def additional_entries16 def additional_entries
5 type = nil17 return [] if slug.start_with?('guide')
6 18
7 doc.children.each_with_object [] do |node, entries|19 css('h3').map do |node|
8 if node.name == 'h1'20 name = node.content.strip
9 type = node.content.strip21 name.sub! %r{\(.*\)}, '()'
10 elsif node.name == 'h3'22 [name, node['id'], "API: #{self.name}"]
11 name = node.content.strip
12 entries << [name, node['id'], type]
13 end
14 end23 end
15 end24 end
16 end25 end
lib/docs/scrapers/vue.rb+10−5
@@ -3,16 +3,21 @@ module Docs · 2 unmodified lines
3 self.name = 'Vue.js'3 self.name = 'Vue.js'
4 self.slug = 'vue'4 self.slug = 'vue'
5 self.type = 'vue'5 self.type = 'vue'
6 self.version = '0.12.5'6 self.version = '0.12.6'
7 self.base_url = 'http://vuejs.org/api/'7 self.base_url = 'http://vuejs.org'
8 8 self.root_path = '/guide/index.html'
9 self.initial_paths = %w(/api/index.html)
10 self.links = {
11 home: 'http://vuejs.org/',
12 code: 'https://github.com/yyx990803/vue'
13 }
9 14
10 html_filters.push 'vue/clean_html', 'vue/entries'15 html_filters.push 'vue/clean_html', 'vue/entries'
11 options[:follow_links] = ->(filter) { filter.root_page? }
12 16
17 options[:only_patterns] = [/\/guide\//, /\/api\//]
13 18
14 options[:attribution] = <<-HTML19 options[:attribution] = <<-HTML
15 &copy; 2014&ndash;2015 Evan You, Vue.js contributors<br>20 &copy; 2013&ndash;2015 Evan You, Vue.js contributors<br>
16 Licensed under the MIT License.21 Licensed under the MIT License.
17 HTML22 HTML
18 end23 end