Skip to content

Commit

Permalink
Support the Jinja2 finalize option
Browse files Browse the repository at this point in the history
  • Loading branch information
dstufft committed Mar 27, 2015
1 parent 4e8347f commit 2191598
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pyramid_jinja2/settings.py
Expand Up @@ -149,6 +149,11 @@ def sget(name, default=None):
# should newstyle gettext calls be enabled?
opts['newstyle'] = asbool(sget('newstyle', False))

# Do we have a finalize function?
finalize = sget('finalize')
if finalize is not None:
opts['finalize'] = maybe_dotted(finalize)

# add custom jinja2 filters
opts['filters'] = parse_named_assetspecs(sget('filters', ''), maybe_dotted)

Expand Down
13 changes: 13 additions & 0 deletions pyramid_jinja2/tests/test_settings.py
Expand Up @@ -143,6 +143,14 @@ def test_most_settings(self):
self.assertEqual(opts['autoescape'], False)
self.assertEqual(opts['cache_size'], 300)
self.assertEqual(opts['gettext'].domain, 'pyramid_jinja2')
self.assertFalse('finalize' in opts)

def test_finalize(self):
settings = {
'j2.finalize': 'pyramid_jinja2.tests.test_settings._fake_finalize',
}
opts = self._callFUT(settings, 'j2.')
self.assertTrue(opts['finalize'] is _fake_finalize)

def test_strict_undefined(self):
from jinja2 import StrictUndefined
Expand All @@ -161,3 +169,8 @@ def test_default_undefined(self):
settings = {'j2.undefined': ''}
opts = self._callFUT(settings, 'j2.')
self.assertEqual(opts['undefined'], Undefined)


# This is just a fake top level name that we can pass into maybe_dotted that
# will resolve.
_fake_finalize = object()

0 comments on commit 2191598

Please sign in to comment.