From 3c0b56497793bbd9ddefb5178bdce72e7e88cc89 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 19 May 2015 15:24:55 +0100 Subject: [PATCH] Whine if there are missing variables that the template needs. --- templating/build.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/templating/build.py b/templating/build.py index 14941cb0..78e48b02 100755 --- a/templating/build.py +++ b/templating/build.py @@ -40,7 +40,7 @@ Checks - Any sections made but not used in the skeleton will produce a warning. """ -from jinja2 import Environment, FileSystemLoader +from jinja2 import Environment, FileSystemLoader, StrictUndefined import internal.units import internal.sections import json @@ -50,15 +50,14 @@ def load_units(): return internal.units.load() def load_sections(env, units): - print "Loading sections..." + print "\nLoading sections..." return internal.sections.load(env, units) def create_from_skeleton(skeleton, sections): - print "Creating spec from skeleton..." + print "\nCreating spec from skeleton..." print "Section keys: %s" % (sections.keys()) return skeleton.render(sections.data) - def check_unaccessed(name, store): unaccessed_keys = store.get_unaccessed_set() if len(unaccessed_keys) > 0: @@ -71,7 +70,10 @@ def main(): return json.dumps(input, indent=4) # make Jinja aware of the templates and filters - env = Environment(loader=FileSystemLoader("templates")) + env = Environment( + loader=FileSystemLoader("templates"), + undefined=StrictUndefined + ) env.filters["jsonify"] = jsonify # load up and parse the lowest single units possible: we don't know or care @@ -87,7 +89,6 @@ def main(): spec = create_from_skeleton(skeleton, sections) check_unaccessed("units", units) - check_unaccessed("sections", sections) with open("spec.rst", "w") as f: f.write(spec)