Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move context logic for layout.html to jinja #1356

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Expand Up @@ -45,6 +45,7 @@ Minor changes
* Python 3.10 added to test matrix (#1334)
* Supplemental Docker setup for development (#1319)
* Most of setup.py migrated to setup.cfg (#1116)
* Jinja2 context variable ``sphinx_version_info`` is now ``(major, minor, -1)``, the patch component is always ``-1``. Reason: It's complicated. (#1345)


Incompatible Changes
Expand Down
9 changes: 0 additions & 9 deletions sphinx_rtd_theme/__init__.py
Expand Up @@ -31,12 +31,6 @@ def config_initiated(app, config):
_('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.')
)


def extend_html_context(app, pagename, templatename, context, doctree):
# Add ``sphinx_version_info`` tuple for use in Jinja templates
context['sphinx_version_info'] = sphinx_version


# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
def setup(app):
if python_version[0] < 3:
Expand Down Expand Up @@ -66,7 +60,4 @@ def setup(app):
else:
app.config.html_add_permalinks = "\uf0c1"

# Extend the default context when rendering the templates.
app.connect("html-page-context", extend_html_context)

return {'parallel_read_safe': True, 'parallel_write_safe': True}
4 changes: 4 additions & 0 deletions sphinx_rtd_theme/layout.html
Expand Up @@ -9,6 +9,10 @@
{%- set lang_attr = 'en' if language == None else (language | replace('_', '-')) %}
{%- set sphinx_writer = 'writer-html5' if html5_doctype else 'writer-html4' -%}

{# Build sphinx_version_info tuple from sphinx_version string in pure Jinja #}
{%- set (_ver_major, _ver_minor) = (sphinx_version.split('.') | list)[:2] | map('int') -%}
{%- set sphinx_version_info = (_ver_major, _ver_minor, -1) -%}

<!DOCTYPE html>
<html class="{{ sphinx_writer }}" lang="{{ lang_attr }}" >
<head>
Expand Down