Skip to content

Commit 8ea0835

Browse files
committed
Allow any files to be rendered as jinja templates
by including a comment ".. jinja" anywhere in the file. By convention, this should be at the top. os.getenv will use this so it can render a 'supported boards' list.
1 parent 4a21e05 commit 8ea0835

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

docs/rstjinja.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Derived from code on Eric Holscher's blog, found at:
22
# https://www.ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/
33

4+
import re
5+
6+
def render_with_jinja(docname, source):
7+
if "shared-bindings/support_matrix" in docname:
8+
return True
9+
if re.search('^\s+.. jinja$', source[0], re.M):
10+
return True
11+
return False
12+
413
def rstjinja(app, docname, source):
514
"""
615
Render our pages as a jinja template for fancy templating goodness.
@@ -9,12 +18,12 @@ def rstjinja(app, docname, source):
918
if app.builder.format not in ("html", "latex"):
1019
return
1120

12-
# we only want our one jinja template to run through this func
13-
if "shared-bindings/support_matrix" not in docname:
21+
# we only want specific files to run through this func
22+
if not render_with_jinja(docname, source):
1423
return
1524

1625
src = rendered = source[0]
17-
print(docname)
26+
print(f"rendering {docname} as jinja templates")
1827

1928
if app.builder.format == "html":
2029
rendered = app.builder.templates.render_string(

0 commit comments

Comments
 (0)