Browse Source

Merge pull request #250 from dlex/master

Custom tests support added similar to custom filters
main
Lakshmi 9 years ago
parent
commit
82d58681c2
1 changed files with 11 additions and 0 deletions
  1. +11
    -0
      hyde/ext/templates/jinja.py

+ 11
- 0
hyde/ext/templates/jinja.py View File

@@ -709,6 +709,7 @@ class Jinja2Template(Template):
settings['extensions'] = list()
settings['extensions'].extend(default_extensions)
settings['filters'] = {}
settings['tests'] = {}

conf = {}

@@ -735,6 +736,15 @@ class Jinja2Template(Template):
module = __import__(module_name, fromlist=[function_name])
settings['filters'][name] = getattr(module, function_name)

tests = conf.get('tests', {})
if isinstance(tests, dict):
for name, value in tests.items():
parts = value.split('.')
module_name = '.'.join(parts[:-1])
function_name = parts[-1]
module = __import__(module_name, fromlist=[function_name])
settings['tests'][name] = getattr(module, function_name)

self.env = Environment(
loader=self.loader,
undefined=SilentUndefined,
@@ -758,6 +768,7 @@ class Jinja2Template(Template):
self.env.filters['islice'] = islice
self.env.filters['top'] = top
self.env.filters.update(settings['filters'])
self.env.tests.update(settings['tests'])

config = {}
if hasattr(site, 'config'):


Loading…
Cancel
Save