Unified · Split
| @@ -3,16 +3,19 @@ module Docs · 2 unmodified lines | |||
| 3 | class << self | 3 | class << self |
| 4 | attr_accessor :params | 4 | attr_accessor :params |
| 5 | attr_accessor :headers | 5 | attr_accessor :headers |
| 6 | attr_accessor :force_gzip | ||
| 6 | 7 | ||
| 7 | def inherited(subclass) | 8 | def inherited(subclass) |
| 8 | super | 9 | super |
| 9 | subclass.params = params.deep_dup | 10 | subclass.params = params.deep_dup |
| 10 | subclass.headers = headers.deep_dup | 11 | subclass.headers = headers.deep_dup |
| 12 | subclass.force_gzip = force_gzip | ||
| 11 | end | 13 | end |
| 12 | end | 14 | end |
| 13 | 15 | ||
| 14 | self.params = {} | 16 | self.params = {} |
| 15 | self.headers = { 'User-Agent' => 'DevDocs' } | 17 | self.headers = { 'User-Agent' => 'DevDocs' } |
| 18 | self.force_gzip = false | ||
| 16 | 19 | ||
| 17 | private | 20 | private |
| 18 | 21 | ||
| @@ -25,7 +28,9 @@ module Docs · 6 unmodified lines | |||
| 25 | end | 28 | end |
| 26 | 29 | ||
| 27 | def request_options | 30 | def request_options |
| 28 | { params: self.class.params, headers: self.class.headers } | 31 | options = { params: self.class.params, headers: self.class.headers } |
| 32 | options[:accept_encoding] = 'gzip' if self.class.force_gzip | ||
| 33 | options | ||
| 29 | end | 34 | end |
| 30 | 35 | ||
| 31 | def process_response?(response) | 36 | def process_response?(response) |
| @@ -12,9 +12,11 @@ module Docs · 11 unmodified lines | |||
| 12 | css('pre').each do |node| | 12 | css('pre').each do |node| |
| 13 | node.inner_html = node.inner_html.strip_heredoc | 13 | node.inner_html = node.inner_html.strip_heredoc |
| 14 | 14 | ||
| 15 | if node['class'].include?('lang-c++') | 15 | next unless node['class'] |
| 16 | |||
| 17 | if node['class'] =~ /lang-c++/i | ||
| 16 | node['data-language'] = 'cpp' | 18 | node['data-language'] = 'cpp' |
| 17 | elsif node['class'].include?('lang-python') | 19 | elsif node['class'] =~ /lang-python/i |
| 18 | node['data-language'] = 'python' | 20 | node['data-language'] = 'python' |
| 19 | end | 21 | end |
| 20 | end | 22 | end |
| @@ -9,13 +9,21 @@ module Docs · 8 unmodified lines | |||
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | def get_type | 11 | def get_type |
| 12 | type = name.dup | 12 | if subpath.start_with?('tutorials') |
| 13 | type.remove! %r{\ \(.*\)} | 13 | 'Tutorials' |
| 14 | type.remove! 'tensorflow::' | 14 | elsif subpath.start_with?('how_tos') |
| 15 | type | 15 | 'How-Tos' |
| 16 | else | ||
| 17 | type = name.dup | ||
| 18 | type.remove! %r{\ \(.*\)} | ||
| 19 | type.remove! 'tensorflow::' | ||
| 20 | type | ||
| 21 | end | ||
| 16 | end | 22 | end |
| 17 | 23 | ||
| 18 | def additional_entries | 24 | def additional_entries |
| 25 | return [] if subpath.start_with?('tutorials') || subpath.start_with?('how_tos') | ||
| 26 | |||
| 19 | css('h2 code', 'h3 code', 'h4 code', 'h5 code').map do |node| | 27 | css('h2 code', 'h3 code', 'h4 code', 'h5 code').map do |node| |
| 20 | name = node.content | 28 | name = node.content |
| 21 | name.sub! %r{\(.*}, '()' | 29 | name.sub! %r{\(.*}, '()' |
| @@ -4,6 +4,7 @@ module Docs · 3 unmodified lines | |||
| 4 | self.type = 'npm' | 4 | self.type = 'npm' |
| 5 | self.release = '3.10.2' | 5 | self.release = '3.10.2' |
| 6 | self.base_url = 'https://docs.npmjs.com/' | 6 | self.base_url = 'https://docs.npmjs.com/' |
| 7 | self.force_gzip = true | ||
| 7 | self.links = { | 8 | self.links = { |
| 8 | home: 'https://www.npmjs.com/', | 9 | home: 'https://www.npmjs.com/', |
| 9 | code: 'https://github.com/npm/npm' | 10 | code: 'https://github.com/npm/npm' |
| @@ -27,11 +28,5 @@ module Docs · 17 unmodified lines | |||
| 27 | Licensed under the npm License.<br> | 28 | Licensed under the npm License.<br> |
| 28 | npm is a trademark of npm, Inc. | 29 | npm is a trademark of npm, Inc. |
| 29 | HTML | 30 | HTML |
| 30 | |||
| 31 | private | ||
| 32 | |||
| 33 | def request_options | ||
| 34 | super.merge accept_encoding: 'gzip' | ||
| 35 | end | ||
| 36 | end | 31 | end |
| 37 | end | 32 | end |
| @@ -2,6 +2,8 @@ module Docs · 1 unmodified line | |||
| 2 | class Tensorflow < UrlScraper | 2 | class Tensorflow < UrlScraper |
| 3 | self.name = 'TensorFlow' | 3 | self.name = 'TensorFlow' |
| 4 | self.type = 'tensorflow' | 4 | self.type = 'tensorflow' |
| 5 | self.root_path = 'index.html' | ||
| 6 | self.force_gzip = true | ||
| 5 | self.links = { | 7 | self.links = { |
| 6 | home: 'https://www.tensorflow.org/', | 8 | home: 'https://www.tensorflow.org/', |
| 7 | code: 'https://github.com/tensorflow/tensorflow' | 9 | code: 'https://github.com/tensorflow/tensorflow' |
| @@ -11,25 +13,33 @@ module Docs · 3 unmodified lines | |||
| 11 | 13 | ||
| 12 | options[:container] = '#content' | 14 | options[:container] = '#content' |
| 13 | 15 | ||
| 16 | options[:fix_urls] = ->(url) do | ||
| 17 | url.sub! %r{\Ahttps://www.tensorflow.org/versions(.+)/([^\.\#]+)(#.*)?\z}, 'https://www.tensorflow.org/versions\1/\2.html\3' | ||
| 18 | url | ||
| 19 | end | ||
| 20 | |||
| 14 | options[:attribution] = <<-HTML | 21 | options[:attribution] = <<-HTML |
| 15 | © 2015 The TensorFlow Authors. All rights reserved.<br> | 22 | © 2015 The TensorFlow Authors. All rights reserved.<br> |
| 16 | Licensed under the Apache 2.0 License. | 23 | Licensed under the Apache 2.0 License. |
| 17 | HTML | 24 | HTML |
| 18 | 25 | ||
| 19 | version 'Python' do | 26 | version 'Python' do |
| 20 | self.base_url = 'https://www.tensorflow.org/versions/r0.10/api_docs/python/' | 27 | self.base_url = 'https://www.tensorflow.org/versions/r0.11/api_docs/python/' |
| 21 | self.release = '0.10' | 28 | self.release = '0.11' |
| 22 | end | 29 | end |
| 23 | 30 | ||
| 24 | version 'C++' do | 31 | version 'C++' do |
| 25 | self.base_url = 'https://www.tensorflow.org/versions/r0.10/api_docs/cc/' | 32 | self.base_url = 'https://www.tensorflow.org/versions/r0.11/api_docs/cc/' |
| 26 | self.release = '0.10' | 33 | self.release = '0.11' |
| 27 | 34 | end | |
| 28 | options[:fix_urls] = ->(url) { | 35 | |
| 29 | url.sub! '/api_docs/cc/class', '/api_docs/cc/Class' | 36 | version 'Guide' do |
| 30 | url.sub! '/api_docs/cc/struct', '/api_docs/cc/Struct' | 37 | self.base_url = 'https://www.tensorflow.org/versions/r0.11/' |
| 31 | url | 38 | self.release = '0.11' |
| 32 | } | 39 | self.root_path = 'tutorials/index.html' |
| 40 | self.initial_paths = %w(how_tos/index.html) | ||
| 41 | |||
| 42 | options[:only_patterns] = [/\Atutorials/, /\Ahow_tos/] | ||
| 33 | end | 43 | end |
| 34 | end | 44 | end |
| 35 | end | 45 | end |