Skip to content

Commit 4206cda

Browse files
committed
docs: tweaking the RTD hack from previous commit
1 parent 1e8a668 commit 4206cda

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

doc/fityk_ext.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@ def setup(app):
4646

4747
# this is hack is needed to use our layout.html on ReadTheDocs
4848
from sphinx.jinja2glue import BuiltinTemplateLoader
49+
from jinja2 import TemplateNotFound
4950
class MyTemplateLoader(BuiltinTemplateLoader):
5051
def get_source(self, environment, template):
51-
print "(MyTemplateLoader.get_source) searching for", template
5252
# If template name in Jinja's "extends" is prepended with "!"
5353
# Sphinx skips project's template paths.
5454
# In BuiltinTemplateLoader self.templatepathlen is used to remove
5555
# project's template paths and leave only Sphinx's paths.
5656
# This hack should leave the last path, so "!layout.html" will find
5757
# the template from Fityk. To avoid recursion, Fityk template
5858
# is not using "!".
59-
self.templatepathlen -= 1
60-
return BuiltinTemplateLoader.get_source(self, environment, template)
61-
self.templatepathlen += 1
62-
59+
print("\n(MyTemplateLoader.get_source) searching for %s" % template)
60+
loaders = self.loaders
61+
# exclamation mark starts search from theme
62+
if template.startswith('!'):
63+
loaders = loaders[self.templatepathlen-1:]
64+
template = template[1:]
65+
for loader in loaders:
66+
print("\ttrying in: %s" % ":".join(loader.searchpath))
67+
try:
68+
return loader.get_source(environment, template)
69+
except TemplateNotFound:
70+
pass
71+
raise TemplateNotFound(template)

0 commit comments

Comments
 (0)