History

Update TensorFlow documentation (0.11)

Thibaut Courouble committed 10 years ago

Commit 0d4c6b51 parent d29d25c5 files · +43 −23Browse files

Unified · Split

5 files
  1. lib/docs/core/scrapers/url_scraper.rb +6 −1
  2. lib/docs/filters/tensorflow/clean_html.rb +4 −2
  3. lib/docs/filters/tensorflow/entries.rb +12 −4
  4. lib/docs/scrapers/npm.rb +1 −6
  5. lib/docs/scrapers/tensorflow.rb +20 −10
lib/docs/core/scrapers/url_scraper.rb+6−1
@@ -3,16 +3,19 @@ module Docs · 2 unmodified lines
33 class << self
44 attr_accessor :params
55 attr_accessor :headers
6+ attr_accessor :force_gzip
67
78 def inherited(subclass)
89 super
910 subclass.params = params.deep_dup
1011 subclass.headers = headers.deep_dup
12+ subclass.force_gzip = force_gzip
1113 end
1214 end
1315
1416 self.params = {}
1517 self.headers = { 'User-Agent' => 'DevDocs' }
18+ self.force_gzip = false
1619
1720 private
1821
@@ -25,7 +28,9 @@ module Docs · 6 unmodified lines
2528 end
2629
2730 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
2934 end
3035
3136 def process_response?(response)
lib/docs/filters/tensorflow/clean_html.rb+4−2
@@ -12,9 +12,11 @@ module Docs · 11 unmodified lines
1212 css('pre').each do |node|
1313 node.inner_html = node.inner_html.strip_heredoc
1414
15− if node['class'].include?('lang-c++')
15+ next unless node['class']
16+
17+ if node['class'] =~ /lang-c++/i
1618 node['data-language'] = 'cpp'
17− elsif node['class'].include?('lang-python')
19+ elsif node['class'] =~ /lang-python/i
1820 node['data-language'] = 'python'
1921 end
2022 end
lib/docs/filters/tensorflow/entries.rb+12−4
@@ -9,13 +9,21 @@ module Docs · 8 unmodified lines
99 end
1010
1111 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
1622 end
1723
1824 def additional_entries
25+ return [] if subpath.start_with?('tutorials') || subpath.start_with?('how_tos')
26+
1927 css('h2 code', 'h3 code', 'h4 code', 'h5 code').map do |node|
2028 name = node.content
2129 name.sub! %r{\(.*}, '()'
lib/docs/scrapers/npm.rb+1−6
@@ -4,6 +4,7 @@ module Docs · 3 unmodified lines
44 self.type = 'npm'
55 self.release = '3.10.2'
66 self.base_url = 'https://docs.npmjs.com/'
7+ self.force_gzip = true
78 self.links = {
89 home: 'https://www.npmjs.com/',
910 code: 'https://github.com/npm/npm'
@@ -27,11 +28,5 @@ module Docs · 17 unmodified lines
2728 Licensed under the npm License.<br>
2829 npm is a trademark of npm, Inc.
2930 HTML
30−
31− private
32−
33− def request_options
34− super.merge accept_encoding: 'gzip'
35− end
3631 end
3732 end
lib/docs/scrapers/tensorflow.rb+20−10
@@ -2,6 +2,8 @@ module Docs · 1 unmodified line
22 class Tensorflow < UrlScraper
33 self.name = 'TensorFlow'
44 self.type = 'tensorflow'
5+ self.root_path = 'index.html'
6+ self.force_gzip = true
57 self.links = {
68 home: 'https://www.tensorflow.org/',
79 code: 'https://github.com/tensorflow/tensorflow'
@@ -11,25 +13,33 @@ module Docs · 3 unmodified lines
1113
1214 options[:container] = '#content'
1315
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+
1421 options[:attribution] = <<-HTML
1522 &copy; 2015 The TensorFlow Authors. All rights reserved.<br>
1623 Licensed under the Apache 2.0 License.
1724 HTML
1825
1926 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'
2229 end
2330
2431 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/]
3343 end
3444 end
3545 end