Skip to content

Commit 1e8a668

Browse files
committed
docs: a hack (to be tested) to include my layout.html from RTD
1 parent 930480d commit 1e8a668

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

doc/conf.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
exclude_patterns = ['html', 'latex']
1313
if not os.getenv('BUILD_WEBSITE'):
1414
exclude_patterns += ['index.rst', 'screens.rst']
15+
1516
if os.getenv('READTHEDOCS'):
1617
# RTD works better with index.html
1718
html_additional_pages = { 'index': '_build/html/fityk-manual.html' }
19+
# RTD has own layout.html. This hack is needed to use all layout.html files.
20+
template_bridge = "fityk_ext.MyTemplateLoader"
21+
1822
templates_path = ['.']
1923
source_suffix = '.rst'
2024
source_encoding = 'utf-8'

doc/fityk_ext.py

+18
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ def setup(app):
4242
app.add_lexer('fityk', FitykLexer());
4343
app.connect('doctree-read', doctree_read)
4444

45+
46+
47+
# this is hack is needed to use our layout.html on ReadTheDocs
48+
from sphinx.jinja2glue import BuiltinTemplateLoader
49+
class MyTemplateLoader(BuiltinTemplateLoader):
50+
def get_source(self, environment, template):
51+
print "(MyTemplateLoader.get_source) searching for", template
52+
# If template name in Jinja's "extends" is prepended with "!"
53+
# Sphinx skips project's template paths.
54+
# In BuiltinTemplateLoader self.templatepathlen is used to remove
55+
# project's template paths and leave only Sphinx's paths.
56+
# This hack should leave the last path, so "!layout.html" will find
57+
# the template from Fityk. To avoid recursion, Fityk template
58+
# is not using "!".
59+
self.templatepathlen -= 1
60+
return BuiltinTemplateLoader.get_source(self, environment, template)
61+
self.templatepathlen += 1
62+

doc/layout.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{% extends "!layout.html" %}
1+
{% extends "sphinxdoc/layout.html" %}
2+
{# "!" (which is handled by sphinx BuiltinTemplateLoader is not used here,
3+
to enable nesting in ReadTheDocs build.
4+
#}
25

36
{% set reldelim1 = ' ' %}
47
{% set reldelim2 = '   ' %}

0 commit comments

Comments
 (0)