diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index c6aab1cf..2cb61408 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -562,8 +562,8 @@ credits = [ ], [ 'TensorFlow', '2015 The TensorFlow Authors', - 'Apache', - 'https://raw.githubusercontent.com/tensorflow/tensorflow/master/LICENSE' + 'CC BY', + 'https://creativecommons.org/licenses/by/3.0/' ], [ 'Twig', '2009-2016 The Twig Team', diff --git a/lib/docs/core/filter.rb b/lib/docs/core/filter.rb index c33a8d15..82788ba0 100644 --- a/lib/docs/core/filter.rb +++ b/lib/docs/core/filter.rb @@ -36,6 +36,10 @@ module Docs context[:root_path] end + def version + context[:version] + end + def subpath @subpath ||= subpath_to(current_url) end diff --git a/lib/docs/core/scraper.rb b/lib/docs/core/scraper.rb index a126299a..63b33e29 100644 --- a/lib/docs/core/scraper.rb +++ b/lib/docs/core/scraper.rb @@ -115,7 +115,8 @@ module Docs def options @options ||= self.class.options.deep_dup.tap do |options| options.merge! base_url: base_url, root_url: root_url, - root_path: root_path, initial_paths: initial_paths + root_path: root_path, initial_paths: initial_paths, + version: self.class.version if root_path? (options[:skip] ||= []).concat ['', '/'] diff --git a/lib/docs/filters/tensorflow/clean_html.rb b/lib/docs/filters/tensorflow/clean_html.rb index 6f20b8e7..cd798220 100644 --- a/lib/docs/filters/tensorflow/clean_html.rb +++ b/lib/docs/filters/tensorflow/clean_html.rb @@ -2,27 +2,43 @@ module Docs class Tensorflow class CleanHtmlFilter < Filter def call - css('hr').remove + @doc = at_css('.devsite-article-inner') - css('pre > code').each do |node| - node.parent['class'] = node['class'] - node.parent.content = node.content + css('hr', '.devsite-nav', '.devsite-content-footer', '.devsite-article-body > br').remove + + css('.devsite-article-body', 'blockquote > blockquote', 'th > h2', 'th > h3').each do |node| + node.before(node.children).remove end - css('pre').each do |node| - node.inner_html = node.inner_html.strip_heredoc + css('code[class] > pre').each do |node| + node = node.parent + node.content = node.content + node.name = 'pre' + end + + css('blockquote > pre:only-child', 'p > pre:only-child').each do |node| + next if node.previous.try(:content).present? || node.next.try(:content).present? + node.parent.before(node).remove + end - next unless node['class'] + css('pre').each do |node| + node.content = node.content.strip_heredoc - if node['class'] =~ /lang-c++/i + if node['class'] && node['class'] =~ /lang-c++/i node['data-language'] = 'cpp' - elsif node['class'] =~ /lang-python/i + elsif node['class'] && node['class'] =~ /lang-python/i node['data-language'] = 'python' + else + node['data-language'] = version == 'Python' ? 'python' : 'cpp' end end - css('b').each do |node| - node.before(node.children).remove + css('code').each do |node| + node.inner_html = node.inner_html.gsub(/\s+/, ' ') + end + + css('> code', '> b').each do |node| + node.replace("

#{node.to_html}

") end doc diff --git a/lib/docs/filters/tensorflow/entries.rb b/lib/docs/filters/tensorflow/entries.rb index 8f71a1b2..53d28e5b 100644 --- a/lib/docs/filters/tensorflow/entries.rb +++ b/lib/docs/filters/tensorflow/entries.rb @@ -5,30 +5,56 @@ module Docs name = at_css('h1').content.strip name.remove! 'class ' name.remove! 'struct ' + name.remove! %r{\.\z} + name.sub! 'tf.contrib', 'contrib' unless version == 'Guide' name end def get_type - if subpath.start_with?('tutorials') - 'Tutorials' - elsif subpath.start_with?('how_tos') - 'How-Tos' + if version == 'Guide' + type = subpath.start_with?('tutorials') ? 'Tutorials' : 'How-Tos' + + if node = at_css('.devsite-nav-item.devsite-nav-active') + node = node.previous_element until !node || node['class'].include?('devsite-nav-item-heading') + type << ": #{node.content}" if node + end + + type + elsif version == 'C++' + name.remove 'tensorflow::' else - type = name.dup - type.remove! %r{\ \(.*\)} - type.remove! 'tensorflow::' + node = at_css('.devsite-nav-item.devsite-nav-active') + node = node.ancestors('.devsite-nav-item').first.at_css('.devsite-nav-title') + type = node.content + type.remove! %r{\.\z} + type.prepend 'Contrib: ' if type.sub!(' (contrib)', '') type end end def additional_entries - return [] if subpath.start_with?('tutorials') || subpath.start_with?('how_tos') + return [] if version == 'Guide' - css('h2 code', 'h3 code', 'h4 code', 'h5 code').map do |node| - name = node.content - name.sub! %r{\(.*}, '()' - name = name.split(' ').last - [name, node.parent['id']] + if version == 'C++' + names = Set.new + css('table.constructors td:first-child code a:first-child', + 'table.methods td:first-child code a:first-child', + 'table.properties td:first-child code a:first-child').each_with_object [] do |node, entries| + name = node.content + name.prepend "#{self.name}::" + name << '()' unless node.ancestors('.properties').present? + next unless names.add?(name) + id = node['href'].remove('#') + entries << [name, id] + end + else + css('h2 code', 'h3 code', 'h4 code', 'h5 code').each_with_object [] do |node, entries| + name = node.content + name.sub! %r{\(.*}, '()' + next if name.include?(' || ') + name = name.split(' ').last + entries << [name, node.parent['id']] + end end end end diff --git a/lib/docs/scrapers/tensorflow.rb b/lib/docs/scrapers/tensorflow.rb index e19a83d0..bd9e913d 100644 --- a/lib/docs/scrapers/tensorflow.rb +++ b/lib/docs/scrapers/tensorflow.rb @@ -11,33 +11,34 @@ module Docs html_filters.push 'tensorflow/entries', 'tensorflow/clean_html' - options[:container] = '#content' + options[:container] = '.devsite-main-content' options[:fix_urls] = ->(url) do - url.sub! %r{\Ahttps://www.tensorflow.org/versions(.+)/([^\.\#]+)(#.*)?\z}, 'https://www.tensorflow.org/versions\1/\2.html\3' + url.sub! 'how_tos/../tutorials', 'tutorials' url end options[:attribution] = <<-HTML © 2015 The TensorFlow Authors. All rights reserved.
- Licensed under the Apache 2.0 License. + Licensed under the Creative Commons Attribution License 3.0.
+ Code samples licensed under the Apache 2.0 License. HTML version 'Python' do - self.base_url = 'https://www.tensorflow.org/versions/r0.11/api_docs/python/' - self.release = '0.11' + self.base_url = 'https://www.tensorflow.org/api_docs/python/' + self.release = '0.12' end version 'C++' do - self.base_url = 'https://www.tensorflow.org/versions/r0.11/api_docs/cc/' - self.release = '0.11' + self.base_url = 'https://www.tensorflow.org/api_docs/cc/' + self.release = '0.12' end version 'Guide' do - self.base_url = 'https://www.tensorflow.org/versions/r0.11/' - self.release = '0.11' - self.root_path = 'tutorials/index.html' - self.initial_paths = %w(how_tos/index.html) + self.base_url = 'https://www.tensorflow.org/' + self.release = '0.12' + self.root_path = 'tutorials/' + self.initial_paths = %w(how_tos/) options[:only_patterns] = [/\Atutorials/, /\Ahow_tos/] end