Index: sitescripts/utils.py |
=================================================================== |
--- a/sitescripts/utils.py |
+++ b/sitescripts/utils.py |
@@ -141,19 +141,30 @@ |
except UnicodeEncodeError: |
return '%s@%s' % (match.group(1).encode('ascii'), |
match.group(2).encode('idna')) |
_template_cache = {} |
def get_template(template, autoescape=True, template_path=siteScriptsPath): |
- """Parses and returns a Jinja2 template""" |
- key = (template_path, template, autoescape) |
- if not key in _template_cache: |
+ """Load Jinja2 template. |
+ |
+ If `template` is a relative path, it's looked up inside `template_path`. |
+ If it's an absolute path, `template_path` is not used. |
+ |
+ Note: Each template will only be loaded once (when first requested). After |
+ that it will be cached and reused -- any changes on the filesystem will be |
+ ignored. |
+ """ |
+ if os.path.isabs(template): |
+ template_path, template = os.path.split(template) |
+ canonical_path = os.path.abspath(os.path.join(template_path, template)) |
+ key = (canonical_path, autoescape) |
Sebastian Noack
2017/03/31 06:33:42
Note that following are NOT equivalent:
get_tem
Vasily Kuznetsov
2017/03/31 16:01:48
Since it's not possible to escape Jinja template e
|
+ if key not in _template_cache: |
if autoescape: |
env = get_template_environment(template_path) |
else: |
env = get_unescaped_template_environment(template_path) |
_template_cache[key] = env.get_template(template) |
return _template_cache[key] |