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: Address reviewer comments on patch set 1 Created March 30, 2017, 6:34 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 canonical_path = os.path.abspath(os.path.join(template_path, template)) 160 template_path = os.path.abspath(template_path)
161 key = (canonical_path, autoescape) 161 key = (template_path, template, 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
162 if key not in _template_cache: 162 if key not in _template_cache:
163 if autoescape: 163 if autoescape:
164 env = get_template_environment(template_path) 164 env = get_template_environment(template_path)
165 else: 165 else:
166 env = get_unescaped_template_environment(template_path) 166 env = get_unescaped_template_environment(template_path)
167 _template_cache[key] = env.get_template(template) 167 _template_cache[key] = env.get_template(template)
168 return _template_cache[key] 168 return _template_cache[key]
169 169
170 170
171 @cached(float('inf')) 171 @cached(float('inf'))
(...skipping 27 matching lines...) Expand all
199 Returns a custom Jinja2 template environment with additional filters. 199 Returns a custom Jinja2 template environment with additional filters.
200 """ 200 """
201 from sitescripts.templateFilters import filters 201 from sitescripts.templateFilters import filters
202 import jinja2 202 import jinja2
203 if not loader: 203 if not loader:
204 loader = jinja2.FileSystemLoader(siteScriptsPath) 204 loader = jinja2.FileSystemLoader(siteScriptsPath)
205 env = jinja2.Environment(loader=loader, autoescape=True) 205 env = jinja2.Environment(loader=loader, autoescape=True)
206 env.filters.update(filters) 206 env.filters.update(filters)
207 env.filters.update(additional_filters) 207 env.filters.update(additional_filters)
208 return env 208 return env
LEFTRIGHT

Powered by Google App Engine
This is Rietveld