From 800c3c1013fbbc487e2a4adf5e6f360fb2be21a4 Mon Sep 17 00:00:00 2001 From: Ivan Oseledets Date: Mon, 7 Sep 2015 23:37:47 +0300 Subject: [PATCH] Add JINJA_TESTS to use custom Jinja2 tests. Refs #1498 --- docs/settings.rst | 1 + pelican/generators.py | 4 ++++ pelican/settings.py | 1 + 3 files changed, 6 insertions(+) diff --git a/docs/settings.rst b/docs/settings.rst index 202fc45f..4526dd16 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -94,6 +94,7 @@ Setting name (followed by default value, if any) control data. For example: ``[".hg", ".git", ".bzr"]`` ``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_TESTS = {}`` A dictionary of custom Jinja2 tests you want to use The dictionary should map the filtername to the filter function. For example: ``{'urlencode': urlencode_filter}`` See `Jinja custom filters documentation`_. diff --git a/pelican/generators.py b/pelican/generators.py index ff9a9d7c..b62bc4b4 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -80,6 +80,10 @@ class Generator(object): custom_filters = self.settings['JINJA_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) def get_template(self, name): diff --git a/pelican/settings.py b/pelican/settings.py index 4d75333a..49336def 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -103,6 +103,7 @@ DEFAULT_CONFIG = { 'MD_EXTENSIONS': ['codehilite(css_class=highlight)', 'extra'], 'JINJA_EXTENSIONS': [], 'JINJA_FILTERS': {}, + 'JINJA_TESTS': {}, 'LOG_FILTER': [], 'LOCALE': [''], # defaults to user locale 'DEFAULT_PAGINATION': False,