Index: sitescripts/utils.py |
=================================================================== |
--- a/sitescripts/utils.py |
+++ b/sitescripts/utils.py |
@@ -114,30 +114,41 @@ def get_template(template, autoescape=Tr |
if not key in _template_cache: |
if autoescape: |
env = get_template_environment() |
else: |
env = get_unescaped_template_environment() |
_template_cache[key] = env.get_template(template) |
return _template_cache[key] |
-@cached(()) |
+@cached(float("inf")) |
def get_template_environment(): |
""" |
Returns a Jinja2 template environment with autoescaping enabled. |
""" |
from sitescripts.templateFilters import filters |
import jinja2 |
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath), autoescape=True, extensions=['jinja2.ext.autoescape']) |
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath), autoescape=True) |
env.filters.update(filters) |
return env |
-@cached(()) |
+@cached(float("inf")) |
def get_unescaped_template_environment(): |
""" |
Returns a Jinja2 template environment without autoescaping. Don't use this to |
generate HTML files! |
""" |
from sitescripts.templateFilters import filters |
import jinja2 |
env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath)) |
env.filters.update(filters) |
return env |
+ |
+def get_custom_template_environment(additional_filters): |
+ """ |
+ Returns a custom Jinja2 template environment with additional filters. |
+ """ |
+ from sitescripts.templateFilters import filters |
+ import jinja2 |
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath), autoescape=True) |
+ env.filters.update(filters) |
+ env.filters.update(additional_filters) |
+ return env |