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

Delta Between Two Patch Sets: cms/converters.py

Issue 29933596: Issue 5333 - Allow cms to generate relative pages (Closed) Base URL: https://hg.adblockplus.org/cms/
Left Patch Set: Address comments on PS2, rearrange test files (again) Created Nov. 7, 2018, 4:14 p.m.
Right Patch Set: Add documentation, remove extraneous global Created Nov. 9, 2018, 8:16 p.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 | « cms/bin/generate_static_pages.py ('k') | cms/utils.py » ('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-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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 self._params['source'] 313 self._params['source']
314 .resolve_link(url, self._params['locale'])) 314 .resolve_link(url, self._params['locale']))
315 315
316 if new_url is not None: 316 if new_url is not None:
317 url = new_url 317 url = new_url
318 if attr == 'href': 318 if attr == 'href':
319 post += ' hreflang="{}"'\ 319 post += ' hreflang="{}"'\
320 .format(jinja2.Markup.escape(locale)) 320 .format(jinja2.Markup.escape(locale))
321 321
322 if self._params['relative']: 322 if self._params['relative']:
323 current_path = '/' + self._params['locale'] 323 current_page = '/{}/{}'.format(self._params['locale'],
324 path = re.search(r'.*/pages(/.*)', 324 self._params['page'])
Vasily Kuznetsov 2018/11/07 18:03:02 This seems fragile: there could be more than one "
rhowell 2018/11/07 20:05:25 Thanks, that's how I had it in patch set 1, but wa
325 self._params['pagedata'][1]) 325 url = make_relative(current_page, url)
326 current_path += path.groups()[0]
327 url = make_relative(current_path, url)
328 326
329 return ''.join((pre, jinja2.Markup.escape(url), post)) 327 return ''.join((pre, jinja2.Markup.escape(url), post))
330 328
331 text = re.sub(r'(<a\s[^<>]*\b(href)=\")([^<>\"]+)(\")', 329 text = re.sub(r'(<a\s[^<>]*\b(href)=\")([^<>\"]+)(\")',
332 process_link, text) 330 process_link, text)
333 text = re.sub(r'(<img\s[^<>]*\b(src)=\")([^<>\"]+)(\")', 331 text = re.sub(r'(<img\s[^<>]*\b(src)=\")([^<>\"]+)(\")',
334 process_link, text) 332 process_link, text)
335 return text 333 return text
336 334
337 include_start_regex = '<' 335 include_start_regex = '<'
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 'linkify': self.linkify, 437 'linkify': self.linkify,
440 'toclist': self.toclist, 438 'toclist': self.toclist,
441 } 439 }
442 440
443 globals = { 441 globals = {
444 'get_string': self.get_string, 442 'get_string': self.get_string,
445 'has_string': self.has_string, 443 'has_string': self.has_string,
446 'get_page_content': self.get_page_content, 444 'get_page_content': self.get_page_content,
447 'get_pages_metadata': self.get_pages_metadata, 445 'get_pages_metadata': self.get_pages_metadata,
448 'get_canonical_url': self.get_canonical_url, 446 'get_canonical_url': self.get_canonical_url,
449 'relative': self._params['relative'],
450 } 447 }
451 448
452 for dirname, dictionary in [('filters', filters), 449 for dirname, dictionary in [('filters', filters),
453 ('globals', globals)]: 450 ('globals', globals)]:
454 for filename in self._params['source'].list_files(dirname): 451 for filename in self._params['source'].list_files(dirname):
455 root, ext = os.path.splitext(filename) 452 root, ext = os.path.splitext(filename)
456 if ext.lower() != '.py': 453 if ext.lower() != '.py':
457 continue 454 continue
458 455
459 path = os.path.join(dirname, filename) 456 path = os.path.join(dirname, filename)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 stack[-1]['subitems'].append(item) 589 stack[-1]['subitems'].append(item)
593 stack.append(item) 590 stack.append(item)
594 return structured 591 return structured
595 592
596 593
597 converters = { 594 converters = {
598 'html': RawConverter, 595 'html': RawConverter,
599 'md': MarkdownConverter, 596 'md': MarkdownConverter,
600 'tmpl': TemplateConverter, 597 'tmpl': TemplateConverter,
601 } 598 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld