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