Add JINJA_TESTS to use custom Jinja2 tests. Refs #1498

This commit is contained in:
Ivan Oseledets 2015-09-07 23:37:47 +03:00
commit 800c3c1013
3 changed files with 6 additions and 0 deletions

View file

@ -94,6 +94,7 @@ Setting name (followed by default value, if any)
control data. For example: ``[".hg", ".git", ".bzr"]`` control data. For example: ``[".hg", ".git", ".bzr"]``
``JINJA_EXTENSIONS = []`` A list of any Jinja2 extensions you want to use. ``JINJA_EXTENSIONS = []`` A list of any Jinja2 extensions you want to use.
``JINJA_FILTERS = {}`` A dictionary of custom Jinja2 filters you want to use. ``JINJA_FILTERS = {}`` A dictionary of custom Jinja2 filters you want to use.
``JINJA_TESTS = {}`` A dictionary of custom Jinja2 tests you want to use
The dictionary should map the filtername to the filter function. The dictionary should map the filtername to the filter function.
For example: ``{'urlencode': urlencode_filter}`` For example: ``{'urlencode': urlencode_filter}``
See `Jinja custom filters documentation`_. See `Jinja custom filters documentation`_.

View file

@ -80,6 +80,10 @@ class Generator(object):
custom_filters = self.settings['JINJA_FILTERS'] custom_filters = self.settings['JINJA_FILTERS']
self.env.filters.update(custom_filters) self.env.filters.update(custom_filters)
# get custom Jinja tests from user settings
custom_tests = self.settings['JINJA_TESTS']
self.env.tests.update(custom_tests)
signals.generator_init.send(self) signals.generator_init.send(self)
def get_template(self, name): def get_template(self, name):

View file

@ -103,6 +103,7 @@ DEFAULT_CONFIG = {
'MD_EXTENSIONS': ['codehilite(css_class=highlight)', 'extra'], 'MD_EXTENSIONS': ['codehilite(css_class=highlight)', 'extra'],
'JINJA_EXTENSIONS': [], 'JINJA_EXTENSIONS': [],
'JINJA_FILTERS': {}, 'JINJA_FILTERS': {},
'JINJA_TESTS': {},
'LOG_FILTER': [], 'LOG_FILTER': [],
'LOCALE': [''], # defaults to user locale 'LOCALE': [''], # defaults to user locale
'DEFAULT_PAGINATION': False, 'DEFAULT_PAGINATION': False,