提交 eb95000e authored 作者: Pascal Lamblin's avatar Pascal Lamblin 提交者: GitHub

Merge pull request #4604 from fvisin/change_theme

Change documentation theme to readthedocs and add source links
/* work around https://github.com/snide/sphinx_rtd_theme/issues/149 */
.rst-content table.field-list .field-body {
padding-top: 8px;
}
// Create version selector for documentation top bar. // Create version selector for documentation top bar.
(function() { (function() {
var url = window.location.href; var url = window.location.href;
...@@ -10,7 +9,7 @@ ...@@ -10,7 +9,7 @@
// If doc is run localy // If doc is run localy
if (url.startsWith('file')) { if (url.startsWith('file')) {
theano_dir = 'html'; theano_dir = 'html';
versions_dir = {"local":"html"}; versions_dir = {"local":"html", "test":"test"};
} }
var root_url = url.substring(0, url.search('/' + theano_dir)) + '/'; var root_url = url.substring(0, url.search('/' + theano_dir)) + '/';
...@@ -28,51 +27,49 @@ ...@@ -28,51 +27,49 @@
versions_dir[ver] = current_version versions_dir[ver] = current_version
} }
function build_select() { function build_vswitch() {
// Build HTML string for version selector combo box and // Build HTML string for version selector, based on ReadTheDocs theme's versions.html
// select current version by iterating versions_dir.
var vswitch = ['<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions" align=left>'];
vswitch.push('<span class="rst-current-version" data-toggle="rst-current-version">');
vswitch.push('<span class="fa fa-book"></span>');
vswitch.push('v:' + current_version);
vswitch.push('<span class="fa fa-caret-down"></span>');
vswitch.push('</span>');
vswitch.push('<div class="rst-other-versions">');
var select = ['<select>']; vswitch.push('<dl>');
vswitch.push('<dt>Versions</dt>');
$.each(versions_dir, function(version, dir){ $.each(versions_dir, function(version, dir){
select.push('<option value="' + version + '"'); var new_url = url.replace(url.match(version_regex)[0],
if (dir == current_version) '/' + versions_dir[version] + '/');
select.push(' selected="selected">' + version + '</option>'); vswitch.push('<dd><a href=' + new_url + '>' + version + '</a></dd>');
else
select.push('>' + version + '</option>');
}); });
vswitch.push('</dl>');
return select.join(''); vswitch.push('<dl>');
} vswitch.push('<dt>Downloads</dt>');
var pdf_url = "http://deeplearning.net/software/theano/theano.pdf"
vswitch.push('<dd><a href=' + pdf_url + '>' + 'PDF' + '</a></dd>');
vswitch.push('</dl>');
function on_switch() { vswitch.push('<dl>');
// Method triggered when an option is selected in combo box. vswitch.push('<dt>On GitHub</dt>');
var selected = $(this).children('option:selected').attr('value'); var git_master = "https://github.com/Theano/Theano"
vswitch.push('<dd><a href=' + git_master + '>' + 'Fork me' + '</a></dd>');
vswitch.push('</dl>');
// Insert selected version in URL. vswitch.push('</div>');
var new_url = url.replace(url.match(version_regex)[0], vswitch.push('</div>');
'/' + versions_dir[selected] + '/');
if (url != new_url) { return vswitch.join('');
$.ajax({
success: function() {
window.location.href = new_url;
},
// If page not in version, go to root of documentation.
error: function() {
window.location.href = root_url + versions_dir[selected] + '/';
}
});
}
} }
// Create combobox HTML, assign to placeholder in layout.html and // Create HTML for version switcher and assign to placeholder in layout.html.
// bind selection method.
$(document).ready(function() { $(document).ready(function() {
// Get theano version.
// var current_version = DOCUMENTATION_OPTIONS.VERSION;
// Build default switcher // Build default switcher
$('.version_switcher_placeholder').html(build_select()); $('.version_switcher_placeholder').html(build_vswitch());
$('.version_switcher_placeholder select').bind('change', on_switch)
// Check server for other doc versions and update switcher. // Check server for other doc versions and update switcher.
if (url.startsWith('http')) { if (url.startsWith('http')) {
...@@ -80,9 +77,7 @@ ...@@ -80,9 +77,7 @@
$.each(data, function(version, dir) { $.each(data, function(version, dir) {
versions_dir[version] = dir; versions_dir[version] = dir;
}); });
$('.version_switcher_placeholder').html(build_vswitch());
$('.version_switcher_placeholder').html(build_select());
$('.version_switcher_placeholder select').bind('change', on_switch)
}); });
} }
}); });
......
{% extends "!layout.html" %} {% extends "!layout.html" %}
{%- block rootrellink %} {% block footer %}
<li>
<span class="version_switcher_placeholder"></span>
</li>
{{ super() }}
{% endblock %}
{%- block extrahead %}
{{ super() }} {{ super() }}
<script type="text/javascript"> <script type="text/javascript">
var _gaq = _gaq || []; var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-168290-9']); _gaq.push(['_setAccount', 'UA-168290-9']);
_gaq.push(['_trackPageview']); _gaq.push(['_trackPageview']);
</script>
<script type="text/javascript" (function() {
src="{{ pathto('_static/version_switch.js', 1) }}"> var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script> </script>
{% endblock %}
{% block footer %} <!--Insert version switcher at bottom of sidebar-->
{{ super() }}
<script type="text/javascript"> <script type="text/javascript">
(function() { var span = document.createElement("SPAN")
var ga = document.createElement('script'); var span_class = document.createAttribute("class");
ga.src = ('https:' == document.location.protocol ? span_class.value = "version_switcher_placeholder";
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; span.setAttributeNode(span_class);
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga); var div = document.createElement("DIV");
})(); var text = document.createTextNode("v:");
var div_class = document.createAttribute("class");
div_class.value = "version-switcher";
div.setAttributeNode(div_class);
var style = document.createAttribute("style");
style.value = "color:#27AA5E; padding-right:5px;";
div.setAttributeNode(style);
var align = document.createAttribute("align");
align.value = "right";
div.setAttributeNode(align);
div.appendChild(text);
div.appendChild(span);
var nav_div = document.getElementsByClassName("wy-nav-side")[0];
nav_div.appendChild(div);
</script>
<script type="text/javascript"
src="{{ pathto('_static/version_switch.js', 1) }}">
</script> </script>
{% endblock %} {% endblock %}
...@@ -22,6 +22,8 @@ from __future__ import absolute_import, print_function, division ...@@ -22,6 +22,8 @@ from __future__ import absolute_import, print_function, division
import os import os
import sys import sys
import theano
theano_path = os.path.join(os.path.dirname(__file__), os.pardir) theano_path = os.path.join(os.path.dirname(__file__), os.pardir)
sys.path.append(os.path.abspath(theano_path)) sys.path.append(os.path.abspath(theano_path))
...@@ -30,7 +32,11 @@ sys.path.append(os.path.abspath(theano_path)) ...@@ -30,7 +32,11 @@ sys.path.append(os.path.abspath(theano_path))
# Add any Sphinx extension module names here, as strings. They can be # Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.doctest', 'sphinx.ext.napoleon'] extensions = ['sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.doctest',
'sphinx.ext.napoleon',
'sphinx.ext.linkcode']
todo_include_todos = True todo_include_todos = True
napoleon_google_docstring = False napoleon_google_docstring = False
...@@ -103,7 +109,20 @@ pygments_style = 'sphinx' ...@@ -103,7 +109,20 @@ pygments_style = 'sphinx'
# must exist either in Sphinx' static/ path, or in one of the custom paths # must exist either in Sphinx' static/ path, or in one of the custom paths
# given in html_static_path. # given in html_static_path.
#html_style = 'default.css' #html_style = 'default.css'
html_theme = 'sphinxdoc' # html_theme = 'sphinxdoc'
# Read the docs style:
if os.environ.get('READTHEDOCS') != 'True':
try:
import sphinx_rtd_theme
except ImportError:
pass # assume we have sphinx >= 1.3
else:
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
html_theme = 'sphinx_rtd_theme'
def setup(app):
app.add_stylesheet("fix_rtd.css")
# The name for this set of Sphinx documents. If None, it defaults to # The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation". # "<project> v<release> documentation".
...@@ -114,8 +133,7 @@ html_theme = 'sphinxdoc' ...@@ -114,8 +133,7 @@ html_theme = 'sphinxdoc'
# The name of an image file (within the static path) to place at the top of # The name of an image file (within the static path) to place at the top of
# the sidebar. # the sidebar.
#html_logo = 'images/theano_logo-200x67.png' html_logo = 'images/theano_logo_allwhite_210x70.png'
html_logo = 'images/theano_logo_allblue_200x46.png'
# The name of an image file (within the static path) to use as favicon of the # The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
...@@ -165,6 +183,35 @@ html_use_smartypants = True ...@@ -165,6 +183,35 @@ html_use_smartypants = True
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'theanodoc' htmlhelp_basename = 'theanodoc'
# Options for the linkcode extension
# ----------------------------------
# Resolve function
# This function is used to populate the (source) links in the API
def linkcode_resolve(domain, info):
def find_source():
# try to find the file and line number, based on code from numpy:
# https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286
obj = sys.modules[info['module']]
for part in info['fullname'].split('.'):
obj = getattr(obj, part)
import inspect
import os
fn = inspect.getsourcefile(obj)
fn = os.path.relpath(fn, start=os.path.dirname(theano.__file__))
source, lineno = inspect.getsourcelines(obj)
return fn, lineno, lineno + len(source) - 1
if domain != 'py' or not info['module']:
return None
try:
filename = 'theano/%s#L%d-L%d' % find_source()
except Exception:
filename = info['module'].replace('.', '/') + '.py'
import subprocess
tag = subprocess.Popen(['git', 'rev-parse', 'HEAD'],
stdout=subprocess.PIPE,
universal_newlines=True).communicate()[0][:-1]
return "https://github.com/Theano/theano/blob/%s/%s" % (tag, filename)
# Options for LaTeX output # Options for LaTeX output
# ------------------------ # ------------------------
......
...@@ -239,10 +239,10 @@ StackOverflow, follow their guidance for `answering questions <http://stackoverf ...@@ -239,10 +239,10 @@ StackOverflow, follow their guidance for `answering questions <http://stackoverf
introduction introduction
install install
tutorial/index tutorial/index
library/index
optimizations
extending/index extending/index
dev_start_guide dev_start_guide
optimizations
library/index
glossary glossary
links links
internal/index internal/index
......
.. _libdoc: .. _libdoc:
.. _Library documentation:
===================== =================
Library Documentation API Documentation
===================== =================
This documentation covers Theano module-wise. This is suited to finding the This documentation covers Theano module-wise. This is suited to finding the
Types and Ops that you can use to build and compile expression graphs. Types and Ops that you can use to build and compile expression graphs.
...@@ -11,20 +12,20 @@ Types and Ops that you can use to build and compile expression graphs. ...@@ -11,20 +12,20 @@ Types and Ops that you can use to build and compile expression graphs.
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
tensor/index compile/index
gradient
config config
printing
d3viz/index d3viz/index
compile/index
gpuarray/index
sparse/index
sparse/sandbox
scalar/index
gof/index gof/index
gpuarray/index
gradient
misc/pkl_utils misc/pkl_utils
scan printing
sandbox/index sandbox/index
scalar/index
scan
sparse/index
sparse/sandbox
tensor/index
typed_list typed_list
There are also some top-level imports that you might find more convenient: There are also some top-level imports that you might find more convenient:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论