Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: sitescripts/utils.py

Issue 29398791: Issue 5044 - Support absolute paths for Jinja templates (Closed)
Left Patch Set: Created March 30, 2017, 5:13 p.m.
Right Patch Set: Address review feedback on patch set 2 Created March 31, 2017, 4 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | tests/test_utils.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2017 eyeo GmbH 2 # Copyright (C) 2006-2017 eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 If `template` is a relative path, it's looked up inside `template_path`. 151 If `template` is a relative path, it's looked up inside `template_path`.
152 If it's an absolute path, `template_path` is not used. 152 If it's an absolute path, `template_path` is not used.
153 153
154 Note: Each template will only be loaded once (when first requested). After 154 Note: Each template will only be loaded once (when first requested). After
155 that it will be cached and reused -- any changes on the filesystem will be 155 that it will be cached and reused -- any changes on the filesystem will be
156 ignored. 156 ignored.
157 """ 157 """
158 if os.path.isabs(template): 158 if os.path.isabs(template):
159 template_path, template = os.path.split(template) 159 template_path, template = os.path.split(template)
160 template_path = os.path.abspath(template_path)
160 key = (template_path, template, autoescape) 161 key = (template_path, template, autoescape)
Wladimir Palant 2017/03/30 17:47:42 This caching key wasn't entirely correct before, a
Vasily Kuznetsov 2017/03/30 18:35:53 Done
161 if key not in _template_cache: 162 if key not in _template_cache:
Sebastian Noack 2017/03/30 17:41:24 Assuming this was the only occurrence of `not x in
Vasily Kuznetsov 2017/03/30 18:35:53 Done
162 if autoescape: 163 if autoescape:
163 env = get_template_environment(template_path) 164 env = get_template_environment(template_path)
164 else: 165 else:
165 env = get_unescaped_template_environment(template_path) 166 env = get_unescaped_template_environment(template_path)
166 _template_cache[key] = env.get_template(template) 167 _template_cache[key] = env.get_template(template)
167 return _template_cache[key] 168 return _template_cache[key]
168 169
169 170
170 @cached(float('inf')) 171 @cached(float('inf'))
171 def get_template_environment(template_path): 172 def get_template_environment(template_path):
(...skipping 26 matching lines...) Expand all
198 Returns a custom Jinja2 template environment with additional filters. 199 Returns a custom Jinja2 template environment with additional filters.
199 """ 200 """
200 from sitescripts.templateFilters import filters 201 from sitescripts.templateFilters import filters
201 import jinja2 202 import jinja2
202 if not loader: 203 if not loader:
203 loader = jinja2.FileSystemLoader(siteScriptsPath) 204 loader = jinja2.FileSystemLoader(siteScriptsPath)
204 env = jinja2.Environment(loader=loader, autoescape=True) 205 env = jinja2.Environment(loader=loader, autoescape=True)
205 env.filters.update(filters) 206 env.filters.update(filters)
206 env.filters.update(additional_filters) 207 env.filters.update(additional_filters)
207 return env 208 return env
LEFTRIGHT

Powered by Google App Engine
This is Rietveld