History

cypress: finish scraper and filters

Jasper van Merle committed 7 years ago

Commit 11234ec1 parent f1887bc4 files · +36 −25Browse files

Unified · Split

4 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +6 −0
  2. lib/docs/filters/cypress/clean_html.rb +12 −3
  3. lib/docs/filters/cypress/entries.rb +0 −7
  4. lib/docs/scrapers/cypress.rb +18 −15
assets/javascripts/templates/pages/about_tmpl.coffee+6−0
@@ -202,6 +202,12 @@ credits = [ · 201 unmodified lines
202 'Apache',202 'Apache',
203 'https://raw.githubusercontent.com/crystal-lang/crystal/master/LICENSE'203 'https://raw.githubusercontent.com/crystal-lang/crystal/master/LICENSE'
204 ], [204 ], [
205 'Cypress',
206 '2017 Cypress.io',
207 'MIT',
208 'https://raw.githubusercontent.com/cypress-io/cypress-documentation/develop/LICENSE.md'
209 ],
210 [
205 'D',211 'D',
206 '1999-2018 The D Language Foundation',212 '1999-2018 The D Language Foundation',
207 'Boost',213 'Boost',
lib/docs/filters/cypress/clean_html.rb+12−3
@@ -4,12 +4,21 @@ module Docs · 3 unmodified lines
4 class Cypress4 class Cypress
5 class CleanHtmlFilter < Filter5 class CleanHtmlFilter < Filter
6 def call6 def call
7 article_div = at_css('#article > div')
8 @doc = article_div unless article_div.nil?
9
10 header = at_css('h1.article-title')
11 doc.prepend_child(header) unless header.nil?
12
7 css('.article-edit-link').remove13 css('.article-edit-link').remove
8 css('#sidebar').remove14 css('.article-footer').remove
9 css('article footer').remove
10 css('#article-toc').remove
11 css('.article-footer-updated').remove15 css('.article-footer-updated').remove
12 16
17 css('pre').each do |node|
18 node.content = node.content
19 node['data-language'] = 'javascript'
20 end
21
13 doc22 doc
14 end23 end
15 end24 end
lib/docs/filters/cypress/entries.rb+0−7
@@ -8,7 +8,6 @@ module Docs · 7 unmodified lines
8 core-concepts8 core-concepts
9 cypress-api9 cypress-api
10 events10 events
11 examples
12 getting-started11 getting-started
13 guides12 guides
14 overview13 overview
@@ -30,12 +29,6 @@ module Docs · 15 unmodified lines
30 end29 end
31 end30 end
32 end31 end
33
34 def additional_entries
35 css('.sidebar-li > a').map do |node|
36 [node['href']]
37 end
38 end
39 end32 end
40 end33 end
41end34end
lib/docs/scrapers/cypress.rb+18−15
@@ -2,32 +2,35 @@ · 1 unmodified line
2 2
3module Docs3module Docs
4 class Cypress < UrlScraper4 class Cypress < UrlScraper
5 # Follow the instructions on https://github.com/cypress-io/cypress-documentation/blob/develop/CONTRIBUTING.md
6 # to run the cypress documentation server locally in the following URL:
7 # self.base_url = 'http://localhost:2222'
8 self.base_url = 'https://docs.cypress.io'
9
10 self.name = 'Cypress'5 self.name = 'Cypress'
11 self.type = 'cypress'6 self.type = 'cypress'
7 self.release = '3.4.1'
8 self.base_url = 'https://docs.cypress.io'
12 self.root_path = '/api/api/table-of-contents.html'9 self.root_path = '/api/api/table-of-contents.html'
10 self.links = {
11 home: 'https://www.cypress.io/',
12 code: 'https://github.com/cypress-io/cypress',
13 }
13 14
14 html_filters.push 'cypress/clean_html', 'cypress/entries'15 html_filters.push 'cypress/entries', 'cypress/clean_html'
15 16
16 options[:root_title] = 'Cypress'
17 options[:container] = '#content'17 options[:container] = '#content'
18 18 options[:max_image_size] = 300_000
19 options[:include_default_entry] = true19 options[:include_default_entry] = true
20 20
21 options[:skip_link] = lambda do |link|21 options[:skip_patterns] = [/examples\//]
22 options[:skip_link] = ->(link) {
22 href = link.attr(:href)23 href = link.attr(:href)
23 24 href.nil? ? true : EntriesFilter::SECTIONS.none? { |section| href.match?("/#{section}/") }
24 EntriesFilter::SECTIONS.none? { |section| href.match?("/#{section}/") }25 }
25 end
26 26
27 options[:attribution] = <<-HTML27 options[:attribution] = <<-HTML
28 © 2018 <a href="https://cypress.io">Cypress.io</a>28 &copy; 2017 Cypress.io<br>
29 - Licensed under the29 Licensed under the MIT License.
30 <a href="https://github.com/cypress-io/cypress-documentation/blob/develop/LICENSE.md">MIT License</a>.
31 HTML30 HTML
31
32 def get_latest_version(opts)
33 get_latest_github_release('cypress-io', 'cypress', opts)
34 end
32 end35 end
33end36end