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

Side by Side Diff: cms/converters.py

Issue 29469568: Issue 5331 - Adds has_string() global (Closed)
Patch Set: Created June 20, 2017, 2:51 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 | tests/expected_output/global » ('j') | tests/test_site/pages/global.tmpl » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 Converter.__init__(self, *args, **kwargs) 374 Converter.__init__(self, *args, **kwargs)
375 375
376 filters = { 376 filters = {
377 'translate': self.translate, 377 'translate': self.translate,
378 'linkify': self.linkify, 378 'linkify': self.linkify,
379 'toclist': self.toclist, 379 'toclist': self.toclist,
380 } 380 }
381 381
382 globals = { 382 globals = {
383 'get_string': self.get_string, 383 'get_string': self.get_string,
384 'has_string': self.has_string,
384 'get_page_content': self.get_page_content, 385 'get_page_content': self.get_page_content,
385 } 386 }
386 387
387 for dirname, dictionary in [('filters', filters), 388 for dirname, dictionary in [('filters', filters),
388 ('globals', globals)]: 389 ('globals', globals)]:
389 for filename in self._params['source'].list_files(dirname): 390 for filename in self._params['source'].list_files(dirname):
390 root, ext = os.path.splitext(filename) 391 root, ext = os.path.splitext(filename)
391 if ext.lower() != '.py': 392 if ext.lower() != '.py':
392 continue 393 continue
393 394
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 self._params['page'], name, default, comment, 431 self._params['page'], name, default, comment,
431 self._params['localedata'], html_escapes 432 self._params['localedata'], html_escapes
432 )) 433 ))
433 434
434 def get_string(self, name, page=None): 435 def get_string(self, name, page=None):
435 if page is None: 436 if page is None:
436 page = self._params['page'] 437 page = self._params['page']
437 438
438 localedata = self._params['source'].read_locale(self._params['locale'], 439 localedata = self._params['source'].read_locale(self._params['locale'],
439 page) 440 page)
440 default = localedata[name] 441 default = localedata[name]
Vasily Kuznetsov 2017/06/20 17:38:27 I didn't pay attention to this line when looking i
441 return jinja2.Markup(self.localize_string( 442 return jinja2.Markup(self.localize_string(
442 page, name, default, '', localedata, html_escapes 443 page, name, default, '', localedata, html_escapes
443 )) 444 ))
444 445
446 def has_string(self, name, page=None):
447 if page is None:
448 page = self._params['page']
449
450 localedata = self._params['source'].read_locale(self._params['locale'],
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)
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
445 def get_page_content(self, page, locale=None): 456 def get_page_content(self, page, locale=None):
446 from cms.utils import get_page_params 457 from cms.utils import get_page_params
447 458
448 if locale is None: 459 if locale is None:
449 locale = self._params['locale'] 460 locale = self._params['locale']
450 return get_page_params(self._params['source'], locale, page) 461 return get_page_params(self._params['source'], locale, page)
451 462
452 def linkify(self, page, locale=None, **attrs): 463 def linkify(self, page, locale=None, **attrs):
453 if locale is None: 464 if locale is None:
454 locale = self._params['locale'] 465 locale = self._params['locale']
(...skipping 24 matching lines...) Expand all
479 stack.pop() 490 stack.pop()
480 stack[-1]['subitems'].append(item) 491 stack[-1]['subitems'].append(item)
481 stack.append(item) 492 stack.append(item)
482 return structured 493 return structured
483 494
484 converters = { 495 converters = {
485 'html': RawConverter, 496 'html': RawConverter,
486 'md': MarkdownConverter, 497 'md': MarkdownConverter,
487 'tmpl': TemplateConverter, 498 'tmpl': TemplateConverter,
488 } 499 }
OLDNEW
« no previous file with comments | « no previous file | tests/expected_output/global » ('j') | tests/test_site/pages/global.tmpl » ('J')

Powered by Google App Engine
This is Rietveld