Update TensorFlow documentation (0.12)

pull/566/merge
Thibaut Courouble 8 years ago
parent 7c7e38d321
commit 8147f9f90a

@ -562,8 +562,8 @@ credits = [
], [ ], [
'TensorFlow', 'TensorFlow',
'2015 The TensorFlow Authors', '2015 The TensorFlow Authors',
'Apache', 'CC BY',
'https://raw.githubusercontent.com/tensorflow/tensorflow/master/LICENSE' 'https://creativecommons.org/licenses/by/3.0/'
], [ ], [
'Twig', 'Twig',
'2009-2016 The Twig Team', '2009-2016 The Twig Team',

@ -36,6 +36,10 @@ module Docs
context[:root_path] context[:root_path]
end end
def version
context[:version]
end
def subpath def subpath
@subpath ||= subpath_to(current_url) @subpath ||= subpath_to(current_url)
end end

@ -115,7 +115,8 @@ module Docs
def options def options
@options ||= self.class.options.deep_dup.tap do |options| @options ||= self.class.options.deep_dup.tap do |options|
options.merge! base_url: base_url, root_url: root_url, 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? if root_path?
(options[:skip] ||= []).concat ['', '/'] (options[:skip] ||= []).concat ['', '/']

@ -2,27 +2,43 @@ module Docs
class Tensorflow class Tensorflow
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
css('hr').remove @doc = at_css('.devsite-article-inner')
css('pre > code').each do |node| css('hr', '.devsite-nav', '.devsite-content-footer', '.devsite-article-body > br').remove
node.parent['class'] = node['class']
node.parent.content = node.content css('.devsite-article-body', 'blockquote > blockquote', 'th > h2', 'th > h3').each do |node|
node.before(node.children).remove
end end
css('pre').each do |node| css('code[class] > pre').each do |node|
node.inner_html = node.inner_html.strip_heredoc 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' node['data-language'] = 'cpp'
elsif node['class'] =~ /lang-python/i elsif node['class'] && node['class'] =~ /lang-python/i
node['data-language'] = 'python' node['data-language'] = 'python'
else
node['data-language'] = version == 'Python' ? 'python' : 'cpp'
end end
end end
css('b').each do |node| css('code').each do |node|
node.before(node.children).remove node.inner_html = node.inner_html.gsub(/\s+/, ' ')
end
css('> code', '> b').each do |node|
node.replace("<p>#{node.to_html}</p>")
end end
doc doc

@ -5,30 +5,56 @@ module Docs
name = at_css('h1').content.strip name = at_css('h1').content.strip
name.remove! 'class ' name.remove! 'class '
name.remove! 'struct ' name.remove! 'struct '
name.remove! %r{\.\z}
name.sub! 'tf.contrib', 'contrib' unless version == 'Guide'
name name
end end
def get_type def get_type
if subpath.start_with?('tutorials') if version == 'Guide'
'Tutorials' type = subpath.start_with?('tutorials') ? 'Tutorials' : 'How-Tos'
elsif subpath.start_with?('how_tos')
'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 else
type = name.dup node = at_css('.devsite-nav-item.devsite-nav-active')
type.remove! %r{\ \(.*\)} node = node.ancestors('.devsite-nav-item').first.at_css('.devsite-nav-title')
type.remove! 'tensorflow::' type = node.content
type.remove! %r{\.\z}
type.prepend 'Contrib: ' if type.sub!(' (contrib)', '')
type type
end end
end end
def additional_entries 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| if version == 'C++'
name = node.content names = Set.new
name.sub! %r{\(.*}, '()' css('table.constructors td:first-child code a:first-child',
name = name.split(' ').last 'table.methods td:first-child code a:first-child',
[name, node.parent['id']] '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 end
end end

@ -11,33 +11,34 @@ module Docs
html_filters.push 'tensorflow/entries', 'tensorflow/clean_html' html_filters.push 'tensorflow/entries', 'tensorflow/clean_html'
options[:container] = '#content' options[:container] = '.devsite-main-content'
options[:fix_urls] = ->(url) do 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 url
end end
options[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; 2015 The TensorFlow Authors. All rights reserved.<br> &copy; 2015 The TensorFlow Authors. All rights reserved.<br>
Licensed under the Apache 2.0 License. Licensed under the Creative Commons Attribution License 3.0.<br>
Code samples licensed under the Apache 2.0 License.
HTML HTML
version 'Python' do version 'Python' do
self.base_url = 'https://www.tensorflow.org/versions/r0.11/api_docs/python/' self.base_url = 'https://www.tensorflow.org/api_docs/python/'
self.release = '0.11' self.release = '0.12'
end end
version 'C++' do version 'C++' do
self.base_url = 'https://www.tensorflow.org/versions/r0.11/api_docs/cc/' self.base_url = 'https://www.tensorflow.org/api_docs/cc/'
self.release = '0.11' self.release = '0.12'
end end
version 'Guide' do version 'Guide' do
self.base_url = 'https://www.tensorflow.org/versions/r0.11/' self.base_url = 'https://www.tensorflow.org/'
self.release = '0.11' self.release = '0.12'
self.root_path = 'tutorials/index.html' self.root_path = 'tutorials/'
self.initial_paths = %w(how_tos/index.html) self.initial_paths = %w(how_tos/)
options[:only_patterns] = [/\Atutorials/, /\Ahow_tos/] options[:only_patterns] = [/\Atutorials/, /\Ahow_tos/]
end end

Loading…
Cancel
Save