[MERGE] forward port of branch 8.0 up to 591e329
[odoo/odoo.git] / doc / conf.py
index 4dafec1..b4751fb 100644 (file)
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 import sys, os
+import sphinx
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
@@ -19,12 +20,17 @@ needs_sphinx = '1.1'
 # Add any Sphinx extension module names here, as strings. They can be extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 extensions = [
+    'sphinx.ext.ifconfig',
     'sphinx.ext.todo',
     'sphinx.ext.autodoc',
     'sphinx.ext.intersphinx',
     'odoodoc',
     'patchqueue'
 ]
+if sphinx.__version__.split('.') >= ['1', '2']:
+    # linkcode is only available from Sphinx 1.2
+    extensions.insert(0, 'sphinx.ext.linkcode')
+
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']
@@ -39,17 +45,17 @@ source_suffix = '.rst'
 master_doc = 'index'
 
 # General information about the project.
-project = u'odoo developer documentation'
-copyright = u'2014, OpenERP s.a.'
+project = u'odoo'
+copyright = u'Odoo S.A.'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
 # built documents.
 #
 # The short X.Y version.
-version = '8.0'
+version = 'master'
 # The full version, including alpha/beta/rc tags.
-release = '8.0b1'
+release = 'master'
 
 # There are two options for replacing |today|: either, you set today to some
 # non-false value, then it is used:
@@ -118,6 +124,8 @@ html_static_path = ['_static']
 
 html_style = "odoo.css"
 
+html_add_permalinks = False
+
 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
 # using the given strftime format.
 #html_last_updated_fmt = '%b %d, %Y'
@@ -158,7 +166,72 @@ html_sidebars = {
 # base URL from which the finished HTML is served.
 #html_use_opensearch = ''
 
+latex_elements = {
+    'papersize': r'a4paper',
+    'preamble': u'''\\setcounter{tocdepth}{2}
+''',
+}
+
+# default must be set otherwise ifconfig blows up
+todo_include_todos = False
+
 intersphinx_mapping = {
     'python': ('https://docs.python.org/2/', None),
-    'werkzeug': ('http://werkzeug.pocoo.org/docs/0.9/', None),
+    'werkzeug': ('http://werkzeug.pocoo.org/docs/', None),
+    'sqlalchemy': ('http://docs.sqlalchemy.org/en/rel_0_9/', None),
+    'django': ('https://django.readthedocs.org/en/latest/', None),
 }
+
+github_user = 'odoo'
+github_project = 'odoo'
+
+def setup(app):
+    app.connect('html-page-context', canonicalize)
+    app.add_config_value('canonical_root', None, 'env')
+    app.add_config_value('canonical_branch', 'master', 'env')
+
+    app.connect('html-page-context', versionize)
+    app.add_config_value('versions', '', 'env')
+
+    app.connect('html-page-context', analytics)
+    app.add_config_value('google_analytics_key', False, 'env')
+
+def canonicalize(app, pagename, templatename, context, doctree):
+    """ Adds a 'canonical' URL for the current document in the rendering
+    context. Requires the ``canonical_root`` setting being set. The canonical
+    branch is ``master`` but can be overridden using ``canonical_branch``.
+    """
+    if not app.config.canonical_root:
+        return
+
+    context['canonical'] = _build_url(
+        app.config.canonical_root, app.config.canonical_branch, pagename)
+
+def versionize(app, pagename, templatename, context, doctree):
+    """ Adds a version switcher below the menu, requires ``canonical_root``
+    and ``versions`` (an ordered, space-separated lists of all possible
+    versions).
+    """
+    if not (app.config.canonical_root and app.config.versions):
+        return
+
+    context['versions'] = [
+        (vs, _build_url(app.config.canonical_root, vs, pagename))
+        for vs in app.config.versions.split(',')
+        if vs != app.config.version
+    ]
+
+def analytics(app, pagename, templatename, context, doctree):
+    if not app.config.google_analytics_key:
+        return
+
+    context['google_analytics_key'] = app.config.google_analytics_key
+
+def _build_url(root, branch, pagename):
+    return "{canonical_url}{canonical_branch}/{canonical_page}".format(
+        canonical_url=root,
+        canonical_branch=branch,
+        canonical_page=(pagename + '.html').replace('index.html', '')
+                                           .replace('index/', ''),
+    )
+