jandecaluwe / urubu

A micro CMS for static websites, with a focus on good navigation practices.
urubu.jandecaluwe.com
GNU Affero General Public License v3.0
179 stars 36 forks source link

Add option for jinja2 to fail on undefined vars #47

Closed leouieda closed 8 years ago

leouieda commented 8 years ago

If a variable is missing from a template, the current behavior of urubu is to treat it as an empty string. So if you forget to define (or define it wrong), the resulting HTML will be empty and you might not realize it.

This adds an optional argument to _site.yml called strict_undefined. If omitted or false, urubu behaves normally. If defined and true, then will add undefined=jinja2.StrictUndefined to jinja2.Environment and jinja will fail with an error when an undefined variable is encountered.

I haven't added this to the docs. If you think it's a good option to have, then I'd welcome some pointers as to where I should document this.

jandecaluwe commented 8 years ago

Is it possible to avoid the duplication of code? From the documentation I understand there is also a jinja2.Undefined value for the default behavior. In that case, it is a matter of setting up the undefined argument correctly.

This should be documented in http://urubu.jandecaluwe.com/manual/structure.html#_siteyml currently. (At some point I may factor out the configuration info in a separate chapter).

leouieda commented 8 years ago

@jandecaluwe I have refactored out the duplicate code and wrote a sentence or two describing the new attribute.

Is there a reason why the built HTML files are committed to master? Should I add my updated build files?

jandecaluwe commented 8 years ago

Thanks. I use the docs as part of my tests, ad-hoc as I change things, and in the regression suite. That's why I commit them locally. From master I do a git subtree push to the gh-pages branch.

leouieda commented 8 years ago

OK, I thought it was something like that.

I liked using this flag because it caught a lot of errors in my template that were silently being left blank.