Mercurial > piecrust2
diff piecrust/templating/jinja/environment.py @ 854:08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
- Make a few APIs simpler.
- Content pipelines create their own jobs, so that generator sources can
keep aborting in `getContents`, but rely on their pipeline to generate
pages for baking.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 04 Jun 2017 23:34:28 -0700 |
parents | 2c7e57d80bba |
children | 41b0c94f9833 |
line wrap: on
line diff
--- a/piecrust/templating/jinja/environment.py Sun May 21 00:06:59 2017 -0700 +++ b/piecrust/templating/jinja/environment.py Sun Jun 04 23:34:28 2017 -0700 @@ -2,6 +2,7 @@ import time import email.utils import hashlib +import logging import strict_rfc3339 from jinja2 import Environment from .extensions import get_highlight_css @@ -10,6 +11,9 @@ from piecrust.uriutil import multi_replace +logger = logging.getLogger(__name__) + + class PieCrustEnvironment(Environment): def __init__(self, app, *args, **kwargs): self.app = app @@ -33,6 +37,16 @@ if val is not None: kwargs.setdefault(name, val) + # Undefined behaviour. + undef = app.config.get('jinja/undefined') + if undef == 'logging': + from jinja2 import make_logging_undefined + kwargs.setdefault('undefined', + make_logging_undefined(logger)) + elif undef == 'strict': + from jinja2 import StrictUndefined + kwargs.setdefault('undefined', StrictUndefined) + # Twig trims blocks. if twig_compatibility_mode is True: kwargs['trim_blocks'] = True