Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
853:f070a4fc033c | 854:08e02c2a2a1a |
---|---|
1 import re | 1 import re |
2 import time | 2 import time |
3 import email.utils | 3 import email.utils |
4 import hashlib | 4 import hashlib |
5 import logging | |
5 import strict_rfc3339 | 6 import strict_rfc3339 |
6 from jinja2 import Environment | 7 from jinja2 import Environment |
7 from .extensions import get_highlight_css | 8 from .extensions import get_highlight_css |
8 from piecrust.data.paginator import Paginator | 9 from piecrust.data.paginator import Paginator |
9 from piecrust.rendering import format_text | 10 from piecrust.rendering import format_text |
10 from piecrust.uriutil import multi_replace | 11 from piecrust.uriutil import multi_replace |
12 | |
13 | |
14 logger = logging.getLogger(__name__) | |
11 | 15 |
12 | 16 |
13 class PieCrustEnvironment(Environment): | 17 class PieCrustEnvironment(Environment): |
14 def __init__(self, app, *args, **kwargs): | 18 def __init__(self, app, *args, **kwargs): |
15 self.app = app | 19 self.app = app |
30 'trim_blocks', 'lstrip_blocks', | 34 'trim_blocks', 'lstrip_blocks', |
31 'newline_sequence', 'keep_trailing_newline']: | 35 'newline_sequence', 'keep_trailing_newline']: |
32 val = app.config.get('jinja/' + name) | 36 val = app.config.get('jinja/' + name) |
33 if val is not None: | 37 if val is not None: |
34 kwargs.setdefault(name, val) | 38 kwargs.setdefault(name, val) |
39 | |
40 # Undefined behaviour. | |
41 undef = app.config.get('jinja/undefined') | |
42 if undef == 'logging': | |
43 from jinja2 import make_logging_undefined | |
44 kwargs.setdefault('undefined', | |
45 make_logging_undefined(logger)) | |
46 elif undef == 'strict': | |
47 from jinja2 import StrictUndefined | |
48 kwargs.setdefault('undefined', StrictUndefined) | |
35 | 49 |
36 # Twig trims blocks. | 50 # Twig trims blocks. |
37 if twig_compatibility_mode is True: | 51 if twig_compatibility_mode is True: |
38 kwargs['trim_blocks'] = True | 52 kwargs['trim_blocks'] = True |
39 | 53 |