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

Side by Side Diff: cms/converters.py

Issue 6364489058353152: Issue 2126 - Adapted CMS for living in its own repository rather than sitescripts (Closed)
Patch Set: Added .pyo to ignore files Created March 12, 2015, 4:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cms/bin/test_server.py ('k') | runserver.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import os, imp, re, jinja2, markdown 18 import os, imp, re, jinja2, markdown
19 from ..utils import get_custom_template_environment
20 19
21 # Monkey-patch Markdown's isBlockLevel function to ensure that no paragraphs are 20 # Monkey-patch Markdown's isBlockLevel function to ensure that no paragraphs are
22 # inserted into the <head> tag 21 # inserted into the <head> tag
23 orig_isBlockLevel = markdown.util.isBlockLevel 22 orig_isBlockLevel = markdown.util.isBlockLevel
24 def isBlockLevel(tag): 23 def isBlockLevel(tag):
25 if tag == "head": 24 if tag == "head":
26 return True 25 return True
27 else: 26 else:
28 return orig_isBlockLevel(tag) 27 return orig_isBlockLevel(tag)
29 markdown.util.isBlockLevel = isBlockLevel 28 markdown.util.isBlockLevel = isBlockLevel
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 code = self._params["source"].read_file(path) 218 code = self._params["source"].read_file(path)
220 module = imp.new_module(root.replace("/", ".")) 219 module = imp.new_module(root.replace("/", "."))
221 exec code in module.__dict__ 220 exec code in module.__dict__
222 221
223 func = os.path.basename(root) 222 func = os.path.basename(root)
224 if not hasattr(module, func): 223 if not hasattr(module, func):
225 raise Exception("Expected function %s not found in filter file %s" % (fu nc, filename)) 224 raise Exception("Expected function %s not found in filter file %s" % (fu nc, filename))
226 filters[func] = getattr(module, func) 225 filters[func] = getattr(module, func)
227 filters[func].module_ref = module # Prevent garbage collection 226 filters[func].module_ref = module # Prevent garbage collection
228 227
229 self._env = get_custom_template_environment(filters, self._SourceLoader(self ._params["source"])) 228 self._env = jinja2.Environment(loader=self._SourceLoader(self._params["sourc e"]), autoescape=True)
229 self._env.filters.update(filters)
230 230
231 def get_html(self, source): 231 def get_html(self, source):
232 template = self._env.from_string(source) 232 template = self._env.from_string(source)
233 return template.render(self._params) 233 return template.render(self._params)
234 234
235 def translate(self, name, page=None, links=[]): 235 def translate(self, name, page=None, links=[]):
236 if page == None: 236 if page == None:
237 localedata = self._params["localedata"] 237 localedata = self._params["localedata"]
238 else: 238 else:
239 localedata = self._params["source"].read_locale(self._params["locale"], pa ge) 239 localedata = self._params["source"].read_locale(self._params["locale"], pa ge)
(...skipping 28 matching lines...) Expand all
268 stack.pop() 268 stack.pop()
269 stack[-1]["subitems"].append(item) 269 stack[-1]["subitems"].append(item)
270 stack.append(item) 270 stack.append(item)
271 return structured 271 return structured
272 272
273 converters = { 273 converters = {
274 "raw": RawConverter, 274 "raw": RawConverter,
275 "md": MarkdownConverter, 275 "md": MarkdownConverter,
276 "tmpl": TemplateConverter, 276 "tmpl": TemplateConverter,
277 } 277 }
OLDNEW
« no previous file with comments | « cms/bin/test_server.py ('k') | runserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld