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

Delta Between Two Patch Sets: cms/converters.py

Issue 29469568: Issue 5331 - Adds has_string() global (Closed)
Left Patch Set: Created June 20, 2017, 2:51 p.m.
Right Patch Set: remove de/global.json change string for en/global.json Created June 21, 2017, 10:25 a.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/expected_output/global » ('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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 except KeyError: 401 except KeyError:
402 raise Exception('Expected symbol {} not found' 402 raise Exception('Expected symbol {} not found'
403 ' in {}'.format(name, path)) 403 ' in {}'.format(name, path))
404 404
405 self._env = jinja2.Environment( 405 self._env = jinja2.Environment(
406 loader=SourceTemplateLoader(self._params['source']), 406 loader=SourceTemplateLoader(self._params['source']),
407 autoescape=True) 407 autoescape=True)
408 self._env.filters.update(filters) 408 self._env.filters.update(filters)
409 self._env.globals.update(globals) 409 self._env.globals.update(globals)
410 410
411 def _get_locale_data(self, page):
412 return self._params['source'].read_locale(self._params['locale'], page)
413
411 def get_html(self, source, filename): 414 def get_html(self, source, filename):
412 env = self._env 415 env = self._env
413 code = env.compile(source, None, filename) 416 code = env.compile(source, None, filename)
414 template = jinja2.Template.from_code(env, code, env.globals) 417 template = jinja2.Template.from_code(env, code, env.globals)
415 418
416 try: 419 try:
417 module = template.make_module(self._params) 420 module = template.make_module(self._params)
418 except Exception: 421 except Exception:
419 env.handle_exception() 422 env.handle_exception()
420 423
421 for key, value in module.__dict__.iteritems(): 424 for key, value in module.__dict__.iteritems():
422 if not key.startswith('_'): 425 if not key.startswith('_'):
423 self._params[key] = value 426 self._params[key] = value
424 427
425 result = unicode(module) 428 result = unicode(module)
426 result = self.process_links(result) 429 result = self.process_links(result)
427 return result 430 return result
428 431
429 def translate(self, default, name, comment=None): 432 def translate(self, default, name, comment=None):
430 return jinja2.Markup(self.localize_string( 433 return jinja2.Markup(self.localize_string(
431 self._params['page'], name, default, comment, 434 self._params['page'], name, default, comment,
432 self._params['localedata'], html_escapes 435 self._params['localedata'], html_escapes
433 )) 436 ))
434 437
435 def get_string(self, name, page=None): 438 def get_string(self, name, page=None):
436 if page is None: 439 if page is None:
437 page = self._params['page'] 440 page = self._params['page']
438 441
439 localedata = self._params['source'].read_locale(self._params['locale'], 442 localedata = self._get_locale_data(page)
440 page)
441 default = localedata[name] 443 default = localedata[name]
Vasily Kuznetsov 2017/06/20 17:38:27 I didn't pay attention to this line when looking i
442 return jinja2.Markup(self.localize_string( 444 return jinja2.Markup(self.localize_string(
443 page, name, default, '', localedata, html_escapes 445 page, name, default, '', localedata, html_escapes
444 )) 446 ))
445 447
446 def has_string(self, name, page=None): 448 def has_string(self, name, page=None):
447 if page is None: 449 if page is None:
448 page = self._params['page'] 450 page = self._params['page']
449 451
450 localedata = self._params['source'].read_locale(self._params['locale'], 452 localedata = self._get_locale_data(page)
Vasily Kuznetsov 2017/06/20 17:38:27 Maybe create a small protected method for this log
Jon Sonesen 2017/06/21 07:53:54 yeah, this is good. but what about the if page is
Vasily Kuznetsov 2017/06/21 08:17:00 Yeah, all true. I was thinking to leave that part
451 page) 453 return name in localedata
452 if name in localedata:
Vasily Kuznetsov 2017/06/20 17:38:28 `return name in localedata` would do the same in o
Jon Sonesen 2017/06/21 07:53:54 Acknowledged.
453 return True
454 return False
455 454
456 def get_page_content(self, page, locale=None): 455 def get_page_content(self, page, locale=None):
457 from cms.utils import get_page_params 456 from cms.utils import get_page_params
458 457
459 if locale is None: 458 if locale is None:
460 locale = self._params['locale'] 459 locale = self._params['locale']
461 return get_page_params(self._params['source'], locale, page) 460 return get_page_params(self._params['source'], locale, page)
462 461
463 def linkify(self, page, locale=None, **attrs): 462 def linkify(self, page, locale=None, **attrs):
464 if locale is None: 463 if locale is None:
(...skipping 25 matching lines...) Expand all
490 stack.pop() 489 stack.pop()
491 stack[-1]['subitems'].append(item) 490 stack[-1]['subitems'].append(item)
492 stack.append(item) 491 stack.append(item)
493 return structured 492 return structured
494 493
495 converters = { 494 converters = {
496 'html': RawConverter, 495 'html': RawConverter,
497 'md': MarkdownConverter, 496 'md': MarkdownConverter,
498 'tmpl': TemplateConverter, 497 'tmpl': TemplateConverter,
499 } 498 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld