Skip to content

Document optional types & functions #8185

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

Merged
merged 7 commits into from
Jul 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
jepler committed Jul 20, 2023
commit 8ea0835ff62c487b23e5574e9dce95f9474e0cf9
15 changes: 12 additions & 3 deletions docs/rstjinja.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Derived from code on Eric Holscher's blog, found at:
# https://www.ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/

import re

def render_with_jinja(docname, source):
if "shared-bindings/support_matrix" in docname:
return True
if re.search('^\s+.. jinja$', source[0], re.M):
return True
return False

def rstjinja(app, docname, source):
"""
Render our pages as a jinja template for fancy templating goodness.
Expand All @@ -9,12 +18,12 @@ def rstjinja(app, docname, source):
if app.builder.format not in ("html", "latex"):
return

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

src = rendered = source[0]
print(docname)
print(f"rendering {docname} as jinja templates")

if app.builder.format == "html":
rendered = app.builder.templates.render_string(
Expand Down