Into one file.
# See `attrs` and `types` files for format documentation.
from dataclasses import dataclass
-import jinja2
import markupsafe
-import re
import sys
from typing import List, Dict
+import templates
##
# Parse `attrs` file
# Output HTML
##
-env = jinja2.Environment(
- # Load template files from ./templates/
- loader=jinja2.FileSystemLoader('templates'),
- # Auto-HTML-escape any html or xml files.
- autoescape=jinja2.select_autoescape(['html', 'xml', 'html.j2', 'xml.j2']),
- # Whitespace control
- trim_blocks=True,
- lstrip_blocks=True,
- # Raise exception on any attempt to access undefined variables.
- undefined=jinja2.StrictUndefined,
-)
-template = env.get_template('attrs.html.j2')
+template = templates.env().get_template('attrs.html.j2')
print(template.render(attrs=attrs, types=types))
# Uses `templates/output.html.j2`
# See `outputs` file for format documentation.
-import jinja2
import markupsafe
import re
import sys
from typing import Dict, Tuple
+import templates
HEADER_RE = re.compile(r'^:(?P<params>[^:]+):(?P<format>.*)')
html_descriptions[params] += line
-env = jinja2.Environment(
- # Load template files from ./templates/
- loader=jinja2.FileSystemLoader('templates'),
- # Auto-HTML-escape any html or xml files.
- autoescape=jinja2.select_autoescape(['html', 'xml', 'html.j2', 'xml.j2']),
- # Whitespace control
- trim_blocks=True,
- lstrip_blocks=True,
- # Raise exception on any attempt to access undefined variables.
- undefined=jinja2.StrictUndefined,
-)
-template = env.get_template('output.html.j2')
+template = templates.env().get_template('output.html.j2')
print(template.render(
formats=formats,
# Vouch for the HTML descriptions as being safe and not needing auto-HTML-escaping.
# Generates shapes.html. Takes path to an html.html file to include as argv[1],
# and a shapelist on stdin.
-import jinja2
import markupsafe
import sys
-from typing import List
+import templates
N_PER_ROW = 4
# Use the shapes name in shape list to create the
# contents of an HTML array.
-env = jinja2.Environment(
- # Load template files from ./templates/
- loader=jinja2.FileSystemLoader('templates'),
- # Auto-HTML-escape any html or xml files.
- autoescape=jinja2.select_autoescape(['html', 'xml', 'html.j2', 'xml.j2']),
- # Whitespace control
- trim_blocks=True,
- lstrip_blocks=True,
- # Raise exception on any attempt to access undefined variables.
- undefined=jinja2.StrictUndefined,
-)
-template = env.get_template('shapes.html.j2')
+template = templates.env().get_template('shapes.html.j2')
print(template.render(
html=markupsafe.Markup(open(sys.argv[1]).read()),
rows=chunks(shapes, N_PER_ROW),
--- /dev/null
+import jinja2
+
+def env():
+ return jinja2.Environment(
+ # Load template files from ./templates/
+ loader=jinja2.FileSystemLoader('templates'),
+ # Auto-HTML-escape any html or xml files.
+ autoescape=jinja2.select_autoescape(['html', 'xml', 'html.j2', 'xml.j2']),
+ # Whitespace control
+ trim_blocks=True,
+ lstrip_blocks=True,
+ # Raise exception on any attempt to access undefined variables.
+ undefined=jinja2.StrictUndefined,
+ )