Skip to content

Commit

Permalink
Fix disabled layout.html override for users.
Browse files Browse the repository at this point in the history
Turns out Sphinx only lets you override an HTML template once. Me
overriding it here for the banner prevented users from overriding it
themselves (for adding css files/etc).

Using an alternative approach to inserting the banner HTML in the body
variable: Jinja2 context['body'].
  • Loading branch information
Robpol86 committed Aug 25, 2016
1 parent d5410ab commit cc5ce13
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
8 changes: 0 additions & 8 deletions sphinxcontrib/versioning/_templates/layout.html

This file was deleted.

5 changes: 5 additions & 0 deletions sphinxcontrib/versioning/sphinx_.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def html_page_context(cls, app, pagename, templatename, context, doctree):
context['vhasdoc'] = versions.vhasdoc
context['vpathto'] = versions.vpathto

# Insert banner into body.
if cls.SHOW_BANNER and 'body' in context:
parsed = app.builder.templates.render('banner.html', context)
context['body'] = parsed + context['body']


def setup(app):
"""Called by Sphinx during phase 0 (initialization).
Expand Down
24 changes: 24 additions & 0 deletions tests/test_sphinx/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ def test_versions_override(tmpdir, local_docs):
assert '<li>BitBucket: feature</li>' in contents


def test_layout_override(tmpdir, local_docs):
"""Verify users can still override layout.html.
:param tmpdir: pytest fixture.
:param local_docs: conftest fixture.
"""
versions = Versions([('', 'master', 'heads', 1, 'conf.py')])

local_docs.join('conf.py').write(
'templates_path = ["_templates"]\n'
)
local_docs.ensure('_templates', 'layout.html').write(
'{% extends "!layout.html" %}\n'
'{% block extrahead %}\n'
'<!-- Hidden Message -->\n'
'{% endblock %}\n'
)

target = tmpdir.ensure_dir('target_master')
build(str(local_docs), str(target), versions, 'master', True)
contents = target.join('contents.html').read()
assert '<!-- Hidden Message -->' in contents


def test_subdirs(tmpdir, local_docs, urls):
"""Make sure relative URLs in `versions` works with RST files in subdirectories.
Expand Down

0 comments on commit cc5ce13

Please sign in to comment.