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

Side by Side Diff: cms/converters.py

Issue 29979564: Issue 5452 - Improve CMS API for local link generation (Closed) Base URL: https://hg.adblockplus.org/cms/
Patch Set: Fix spacing in `global` Created Jan. 17, 2019, 3:12 a.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/common/en/global » ('j') | no next file with comments »
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-present eyeo GmbH 2 # Copyright (C) 2006-present 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 'linkify': self.linkify, 435 'linkify': self.linkify,
436 'toclist': self.toclist, 436 'toclist': self.toclist,
437 } 437 }
438 438
439 globals = { 439 globals = {
440 'get_string': self.get_string, 440 'get_string': self.get_string,
441 'has_string': self.has_string, 441 'has_string': self.has_string,
442 'get_page_content': self.get_page_content, 442 'get_page_content': self.get_page_content,
443 'get_pages_metadata': self.get_pages_metadata, 443 'get_pages_metadata': self.get_pages_metadata,
444 'get_canonical_url': self.get_canonical_url, 444 'get_canonical_url': self.get_canonical_url,
445 'get_page_url': self.get_page_url,
446 'page_has_locale': self.page_has_locale,
445 } 447 }
446 448
447 for dirname, dictionary in [('filters', filters), 449 for dirname, dictionary in [('filters', filters),
448 ('globals', globals)]: 450 ('globals', globals)]:
449 for filename in self._params['source'].list_files(dirname): 451 for filename in self._params['source'].list_files(dirname):
450 root, ext = os.path.splitext(filename) 452 root, ext = os.path.splitext(filename)
451 if ext.lower() != '.py': 453 if ext.lower() != '.py':
452 continue 454 continue
453 455
454 path = os.path.join(dirname, filename) 456 path = os.path.join(dirname, filename)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 583
582 structured = [] 584 structured = []
583 stack = [{'level': 0, 'subitems': structured}] 585 stack = [{'level': 0, 'subitems': structured}]
584 for item in flat: 586 for item in flat:
585 while stack[-1]['level'] >= item['level']: 587 while stack[-1]['level'] >= item['level']:
586 stack.pop() 588 stack.pop()
587 stack[-1]['subitems'].append(item) 589 stack[-1]['subitems'].append(item)
588 stack.append(item) 590 stack.append(item)
589 return structured 591 return structured
590 592
593 def page_has_locale(self, page, locale):
594 return self._params['source'].has_locale(locale, page)
595
596 def get_page_url(self, page, locale=None, redirect=False):
597 if not locale:
598 locale = self._params['locale']
599 if self.page_has_locale(page, locale) or redirect:
600 return self._params['source'].resolve_link(page, locale)[1]
601 raise Exception('{} does not exist in {}'.format(page, locale))
602
591 603
592 converters = { 604 converters = {
593 'html': RawConverter, 605 'html': RawConverter,
594 'md': MarkdownConverter, 606 'md': MarkdownConverter,
595 'tmpl': TemplateConverter, 607 'tmpl': TemplateConverter,
596 } 608 }
OLDNEW
« no previous file with comments | « no previous file | tests/expected_output/common/en/global » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld