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

Side by Side Diff: cms/converters.py

Issue 5148261828526080: Issue 2119 - Add get_page_content template function. (Closed)
Patch Set: Addressed Sebastian's feedback. Created April 5, 2015, 1:24 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 | « no previous file | cms/utils.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,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 Converter.__init__(self, *args, **kwargs) 285 Converter.__init__(self, *args, **kwargs)
286 286
287 filters = { 287 filters = {
288 "translate": self.translate, 288 "translate": self.translate,
289 "linkify": self.linkify, 289 "linkify": self.linkify,
290 "toclist": self.toclist, 290 "toclist": self.toclist,
291 } 291 }
292 292
293 globals = { 293 globals = {
294 "get_string": self.get_string, 294 "get_string": self.get_string,
295 "get_page_content": self.get_page_content,
295 } 296 }
296 297
297 for dirname, dictionary in [("filters", filters), ("globals", globals)]: 298 for dirname, dictionary in [("filters", filters), ("globals", globals)]:
298 for filename in self._params["source"].list_files(dirname): 299 for filename in self._params["source"].list_files(dirname):
299 root, ext = os.path.splitext(filename) 300 root, ext = os.path.splitext(filename)
300 if ext.lower() != ".py": 301 if ext.lower() != ".py":
301 continue 302 continue
302 303
303 path = "%s/%s" % (dirname, filename) 304 path = "%s/%s" % (dirname, filename)
304 code = self._params["source"].read_file(path) 305 code = self._params["source"].read_file(path)
(...skipping 30 matching lines...) Expand all
335 # Note: We currently ignore the comment, it is only relevant when 336 # Note: We currently ignore the comment, it is only relevant when
336 # generating the master translation. 337 # generating the master translation.
337 localedata = self._params["localedata"] 338 localedata = self._params["localedata"]
338 return jinja2.Markup(self.localize_string(name, default, localedata, html_es capes)) 339 return jinja2.Markup(self.localize_string(name, default, localedata, html_es capes))
339 340
340 def get_string(self, name, page): 341 def get_string(self, name, page):
341 localedata = self._params["source"].read_locale(self._params["locale"], page ) 342 localedata = self._params["source"].read_locale(self._params["locale"], page )
342 default = localedata[name] 343 default = localedata[name]
343 return jinja2.Markup(self.localize_string(name, default, localedata, html_es capes)) 344 return jinja2.Markup(self.localize_string(name, default, localedata, html_es capes))
344 345
346 def get_page_content(self, page, locale=None):
347 from utils import get_page_params
Wladimir Palant 2015/04/06 19:14:30 That's an implicit relative import. From https://w
kzar 2015/04/07 14:43:56 Done.
348
349 page, ext = os.path.splitext(page)
Wladimir Palant 2015/04/06 19:14:30 We never specify the format as part of the page. Y
kzar 2015/04/07 14:43:56 Done.
350 if locale is None:
351 locale = self._params["locale"]
352 params = get_page_params(self._params["source"], locale, page, ext[1:])
353 return {k: params[k] for k in ("head", "body")}
354
345 def linkify(self, page, locale=None, **attrs): 355 def linkify(self, page, locale=None, **attrs):
346 if locale is None: 356 if locale is None:
347 locale = self._params["locale"] 357 locale = self._params["locale"]
348 358
349 locale, url = self._params["source"].resolve_link(page, locale) 359 locale, url = self._params["source"].resolve_link(page, locale)
350 return jinja2.Markup('<a%s>' % ''.join( 360 return jinja2.Markup('<a%s>' % ''.join(
351 ' %s="%s"' % (name, jinja2.escape(value)) for name, value in [ 361 ' %s="%s"' % (name, jinja2.escape(value)) for name, value in [
352 ('href', url), 362 ('href', url),
353 ('hreflang', locale) 363 ('hreflang', locale)
354 ] + attrs.items() 364 ] + attrs.items()
(...skipping 16 matching lines...) Expand all
371 stack.pop() 381 stack.pop()
372 stack[-1]["subitems"].append(item) 382 stack[-1]["subitems"].append(item)
373 stack.append(item) 383 stack.append(item)
374 return structured 384 return structured
375 385
376 converters = { 386 converters = {
377 "html": RawConverter, 387 "html": RawConverter,
378 "md": MarkdownConverter, 388 "md": MarkdownConverter,
379 "tmpl": TemplateConverter, 389 "tmpl": TemplateConverter,
380 } 390 }
OLDNEW
« no previous file with comments | « no previous file | cms/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld