From 187e09ed93a6eddb75eff502b5a96c918803994c Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Fri, 10 Nov 2017 13:11:57 -0500 Subject: [PATCH] Update Angular documentation (5.0.1) --- lib/docs/scrapers/angular.rb | 68 +++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/lib/docs/scrapers/angular.rb b/lib/docs/scrapers/angular.rb index 8ff7c728..17fd32dc 100644 --- a/lib/docs/scrapers/angular.rb +++ b/lib/docs/scrapers/angular.rb @@ -15,29 +15,13 @@ module Docs Licensed under the Creative Commons Attribution License 4.0. HTML - version do - self.release = '4.4.6' - self.base_url = 'https://angular.io/' - self.root_path = 'docs' - - html_filters.push 'angular/clean_html', 'angular/entries' - - options[:follow_links] = false - options[:only_patterns] = [/\Aguide/, /\Atutorial/, /\Aapi/] - options[:fix_urls_before_parse] = ->(url) do - url.sub! %r{\Aguide/}, '/guide/' - url.sub! %r{\Atutorial/}, '/tutorial/' - url.sub! %r{\Aapi/}, '/api/' - url.sub! %r{\Agenerated/}, '/generated/' - url - end - + module Common private def initial_urls initial_urls = [] - Request.run 'https://angular.io/generated/navigation.json' do |response| + Request.run "#{self.class.base_url}generated/navigation.json" do |response| data = JSON.parse(response.body) dig = ->(entry) do initial_urls << url_for("generated/docs/#{entry['url']}.json") if entry['url'] && entry['url'] != 'api' @@ -46,7 +30,7 @@ module Docs data['SideNav'].each(&dig) end - Request.run 'https://angular.io/generated/docs/api/api-list.json' do |response| + Request.run "#{self.class.base_url}generated/docs/api/api-list.json" do |response| data = JSON.parse(response.body) dig = ->(entry) do initial_urls << url_for("generated/docs/#{entry['path']}.json") if entry['path'] @@ -61,7 +45,11 @@ module Docs def handle_response(response) if response.mime_type.include?('json') - response.options[:response_body] = JSON.parse(response.body)['contents'] + begin + response.options[:response_body] = JSON.parse(response.body)['contents'] + rescue JSON::ParserError + response.options[:response_body] = '' + end response.headers['Content-Type'] = 'text/html' response.url.path = response.url.path.sub('/generated/docs/', '/').remove('.json') response.effective_url.path = response.effective_url.path.sub('/generated/docs/', '/').remove('.json') @@ -70,6 +58,46 @@ module Docs end end + version do + self.release = '5.0.1' + self.base_url = 'https://angular.io/' + self.root_path = 'docs' + + html_filters.push 'angular/clean_html', 'angular/entries' + + options[:follow_links] = false + options[:only_patterns] = [/\Aguide/, /\Atutorial/, /\Aapi/] + options[:fix_urls_before_parse] = ->(url) do + url.sub! %r{\Aguide/}, '/guide/' + url.sub! %r{\Atutorial/}, '/tutorial/' + url.sub! %r{\Aapi/}, '/api/' + url.sub! %r{\Agenerated/}, '/generated/' + url + end + + include Docs::Angular::Common + end + + version '4' do + self.release = '4.4.6' + self.base_url = 'https://v4.angular.io/' + self.root_path = 'docs' + + html_filters.push 'angular/clean_html', 'angular/entries' + + options[:follow_links] = false + options[:only_patterns] = [/\Aguide/, /\Atutorial/, /\Aapi/] + options[:fix_urls_before_parse] = ->(url) do + url.sub! %r{\Aguide/}, '/guide/' + url.sub! %r{\Atutorial/}, '/tutorial/' + url.sub! %r{\Aapi/}, '/api/' + url.sub! %r{\Agenerated/}, '/generated/' + url + end + + include Docs::Angular::Common + end + version '2' do self.release = '2.4.10' self.base_url = 'https://v2.angular.io/docs/ts/latest/'