Skip to content

Commit cc5ce13

Browse files
committed
Fix disabled layout.html override for users.
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'].
1 parent d5410ab commit cc5ce13

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

sphinxcontrib/versioning/_templates/layout.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

sphinxcontrib/versioning/sphinx_.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def html_page_context(cls, app, pagename, templatename, context, doctree):
112112
context['vhasdoc'] = versions.vhasdoc
113113
context['vpathto'] = versions.vpathto
114114

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

116121
def setup(app):
117122
"""Called by Sphinx during phase 0 (initialization).

tests/test_sphinx/test_build.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ def test_versions_override(tmpdir, local_docs):
149149
assert '<li>BitBucket: feature</li>' in contents
150150

151151

152+
def test_layout_override(tmpdir, local_docs):
153+
"""Verify users can still override layout.html.
154+
155+
:param tmpdir: pytest fixture.
156+
:param local_docs: conftest fixture.
157+
"""
158+
versions = Versions([('', 'master', 'heads', 1, 'conf.py')])
159+
160+
local_docs.join('conf.py').write(
161+
'templates_path = ["_templates"]\n'
162+
)
163+
local_docs.ensure('_templates', 'layout.html').write(
164+
'{% extends "!layout.html" %}\n'
165+
'{% block extrahead %}\n'
166+
'<!-- Hidden Message -->\n'
167+
'{% endblock %}\n'
168+
)
169+
170+
target = tmpdir.ensure_dir('target_master')
171+
build(str(local_docs), str(target), versions, 'master', True)
172+
contents = target.join('contents.html').read()
173+
assert '<!-- Hidden Message -->' in contents
174+
175+
152176
def test_subdirs(tmpdir, local_docs, urls):
153177
"""Make sure relative URLs in `versions` works with RST files in subdirectories.
154178

0 commit comments

Comments
 (0)