diff options
| author | Xavier Morel <xmo@odoo.com> | 2015-07-08 11:48:40 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2015-07-08 13:06:10 +0200 |
| commit | 9beaeddf606d0daac589561474a3799bb66f72c1 (patch) | |
| tree | c01620184274e5b4657d93c613a0a91583a0c555 /doc | |
| parent | 91985d7eae34c2c6e1cf7890dd3435e53a966d8d (diff) | |
[FIX] doc: new theme snags
* fix handling of no banner (and no default banner) on documents:
- don't try to build a banner URL at the top of document
- don't build a mini-banner in cards
* fix compatibility between custom HTML translator and domains creating
new nodes (and their rendering): hook translator via
app.add_translator so app.add_node can do the job correctly: with
html_translator_class the application is not aware of the new HTML
translator and add_node can't add the relevant rendering methods
* add translation for line_block and line (classes not used, point is
just to have a div for each line so "newlines" are kept
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/_extensions/odoo/__init__.py | 6 | ||||
| -rw-r--r-- | doc/_extensions/odoo/layout.html | 2 | ||||
| -rw-r--r-- | doc/_extensions/odoo/translator.py | 36 | ||||
| -rw-r--r-- | doc/conf.py | 1 |
4 files changed, 33 insertions, 12 deletions
diff --git a/doc/_extensions/odoo/__init__.py b/doc/_extensions/odoo/__init__.py index 125c2f55afb..e2600d744df 100644 --- a/doc/_extensions/odoo/__init__.py +++ b/doc/_extensions/odoo/__init__.py @@ -1,13 +1,15 @@ # -*- coding: utf-8 -*- -from . import switcher from . import pygments_override -import collections +from . import switcher +from . import translator import sphinx.environment import sphinx.builders.html from docutils import nodes def setup(app): + app.set_translator('html', translator.BootstrapTranslator) + switcher.setup(app) app.add_config_value('odoo_cover_default', None, 'env') app.add_config_value('odoo_cover_external', {}, 'env') diff --git a/doc/_extensions/odoo/layout.html b/doc/_extensions/odoo/layout.html index 0f9661ba6de..c14eab647eb 100644 --- a/doc/_extensions/odoo/layout.html +++ b/doc/_extensions/odoo/layout.html @@ -46,7 +46,7 @@ {%- block header -%} <header class="{{ ' '.join(classes) }}"> <figure class="card top"> - <span class="card-img" style="background-image: url('{{ pathto('_static/' + meta['banner'], True) }}');"></span> + <span class="card-img" {% if meta['banner'] %}style="background-image: url('{{ pathto('_static/' + meta['banner'], True) }}');"{% endif %}></span> </figure> </header> <nav id="main_navbar" class="navbar {{ ' '.join(classes) }}"> diff --git a/doc/_extensions/odoo/translator.py b/doc/_extensions/odoo/translator.py index 681d4456e2f..6bb041e2323 100644 --- a/doc/_extensions/odoo/translator.py +++ b/doc/_extensions/odoo/translator.py @@ -364,6 +364,18 @@ class BootstrapTranslator(nodes.NodeVisitor, object): def visit_legend(self, node): pass def depart_legend(self, node): pass + def visit_line(self, node): + self.body.append(self.starttag(node, 'div', CLASS='line')) + # ensure the line still takes the room it needs + if not len(node): self.body.append(u'<br />') + def depart_line(self, node): + self.body.append(u'</div>') + + def visit_line_block(self, node): + self.body.append(self.starttag(node, 'div', CLASS='line-block')) + def depart_line_block(self, node): + self.body.append(u'</div>') + def visit_table(self, node): self.body.append(self.starttag(node, 'table', CLASS='table')) def depart_table(self, node): @@ -591,23 +603,31 @@ class BootstrapTranslator(nodes.NodeVisitor, object): entries = [(title, ref)] if not toc else ((e[0], e[1]) for e in toc[0]['entries']) for subtitle, subref in entries: + baseuri = self.builder.get_target_uri(node['parent']) + if subref in env.metadata: cover = env.metadata[subref].get('banner', conf.odoo_cover_default) elif subref in conf.odoo_cover_external: cover = conf.odoo_cover_external[subref] else: cover = conf.odoo_cover_default_external - banner = '_static/' + cover - base, ext = os.path.splitext(banner) - small = "{}.small{}".format(base, ext) - if os.path.isfile(urllib.url2pathname(small)): - banner = small - baseuri = self.builder.get_target_uri(node['parent']) + + if cover: + banner = '_static/' + cover + base, ext = os.path.splitext(banner) + small = "{}.small{}".format(base, ext) + if os.path.isfile(urllib.url2pathname(small)): + banner = small + style = u"background-image: url('{}')".format( + util.relative_uri(baseuri, banner) or '#') + else: + style = u'' + self.body.append(u""" <div class="col-sm-6 col-md-3"> <figure class="card"> <a href="{link}" class="card-img"> - <span style="background-image: url('{banner}')"></span> + <span style="{style}"></span> <figcaption>{title}</figcaption> </a> </figure> @@ -615,7 +635,7 @@ class BootstrapTranslator(nodes.NodeVisitor, object): """.format( link=subref if util.url_re.match(subref) else util.relative_uri( baseuri, self.builder.get_target_uri(subref)), - banner=util.relative_uri(baseuri, banner) or '#', + style=style, title=subtitle if subtitle else util.nodes.clean_astext(env.titles[subref]), )) diff --git a/doc/conf.py b/doc/conf.py index 8ae57282314..bffee53df33 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -92,7 +92,6 @@ pygments_style = 'odoo' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'odoo' -html_translator_class = 'odoo.translator.BootstrapTranslator' odoo_cover_default = 'banners/installing_odoo.jpg' odoo_cover_external = { |
