Skip to content

Commit

Permalink
Jinja2: enabled extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kolypto committed Apr 28, 2019
1 parent 6afe51c commit f042b46
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.3.8 (2019-04-29)
* Enabled Jinja2 extensions: i18n, do, loopcontrols

## 0.3.7 (2019-04-23)
* The new `{{ VAR_NAME |env }}` filter lets you use environment variables in every template.

Expand Down
8 changes: 8 additions & 0 deletions j2cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ def get_source(self, environment, template):
class Jinja2TemplateRenderer(object):
""" Template renderer """

ENABLED_EXTENSIONS=(
# TODO: some day, we will load custom extensions from the CLI. Will we?
'jinja2.ext.i18n',
'jinja2.ext.do',
'jinja2.ext.loopcontrols',
)

def __init__(self, cwd, allow_undefined):
self._env = jinja2.Environment(
extensions=self.ENABLED_EXTENSIONS,
loader=FilePathLoader(cwd),
undefined=jinja2.Undefined if allow_undefined else jinja2.StrictUndefined, # raise errors for undefineds?
keep_trailing_newline=True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name='j2cli',
version='0.3.7',
version='0.3.8',
author='Mark Vartanyan',
author_email='[email protected]',

Expand Down
5 changes: 5 additions & 0 deletions tests/render-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,8 @@ def test_undefined(self):
self.assertRaises(UndefinedError, self._testme, ['resources/name.j2'], u'Hello !\n', env=dict())
# `name` undefined: no error
self._testme(['--undefined', 'resources/name.j2'], u'Hello !\n', env=dict())

def test_jinja2_extensions(self):
with mktemp('{% do [] %}') as template:
# `do` tag is an extension
self._testme([template], '')

0 comments on commit f042b46

Please sign in to comment.