1
0
Fork 0
forked from github/pelican

Provide a plugin_enabled Jinja test for themes

This commit is contained in:
Deniz Turgut 2023-11-01 22:49:15 +03:00
commit feae8ef41c
No known key found for this signature in database
GPG key ID: 87B7168D7AB3ED2F
5 changed files with 143 additions and 1 deletions

View file

@ -1581,6 +1581,31 @@ class TestJinja2Environment(TestCaseWithCLocale):
self._test_jinja2_helper(settings, content, expected)
def test_jinja2_filter_plugin_enabled(self):
"""JINJA_FILTERS adds custom filters to Jinja2 environment"""
settings = {"PLUGINS": ["legacy_plugin", "pelican.plugins.ns_plugin"]}
jinja_template = (
"{plugin}: "
"{{% if '{plugin}' is plugin_enabled %}}yes"
"{{% else %}}no{{% endif %}}"
)
content = " / ".join(
(
jinja_template.format(plugin="ns_plugin"),
jinja_template.format(plugin="pelican.plugins.ns_plugin"),
jinja_template.format(plugin="legacy_plugin"),
jinja_template.format(plugin="unknown"),
)
)
expected = (
"ns_plugin: yes / "
"pelican.plugins.ns_plugin: yes / "
"legacy_plugin: yes / "
"unknown: no"
)
self._test_jinja2_helper(settings, content, expected)
def test_jinja2_test(self):
"""JINJA_TESTS adds custom tests to Jinja2 environment"""
content = "foo {{ foo is custom_test }}, bar {{ bar is custom_test }}"