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: Translate rel_path Created Nov. 8, 2018, 2:48 a.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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 Exception 174 Exception
175 If the default is required but cannot be obtained. 175 If the default is required but cannot be obtained.
176 176
177 """ 177 """
178 def escape(s): 178 def escape(s):
179 return ''.join(escapes.get(c, c) for c in s) 179 return ''.join(escapes.get(c, c) for c in s)
180 180
181 def re_escape(s): 181 def re_escape(s):
182 return re.escape(escape(s)) 182 return re.escape(escape(s))
183 183
184 # import ipdb; ipdb.set_trace()
Vasily Kuznetsov 2018/11/08 14:36:14 Oops
rhowell 2018/11/08 20:05:18 Done.
185 locale = self._params['locale'] 184 locale = self._params['locale']
186 localedata = self._get_locale_data(page, locale) 185 localedata = self._get_locale_data(page, locale)
187 defaultlocale = self._params['defaultlocale'] 186 defaultlocale = self._params['defaultlocale']
188 default_localedata = self._get_locale_data(page, defaultlocale) 187 default_localedata = self._get_locale_data(page, defaultlocale)
189 188
190 if default: 189 if default:
191 # The default is provided in the page: remember it, in case the 190 # The default is provided in the page: remember it, in case the
192 # same string name is used again in this page. 191 # same string name is used again in this page.
193 self._seen_defaults[(page, name)] = (default, comment) 192 self._seen_defaults[(page, name)] = (default, comment)
194 elif (page, name) in self._seen_defaults: 193 elif (page, name) in self._seen_defaults:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 ) 299 )
301 300
302 def process_links(self, text): 301 def process_links(self, text):
303 def make_relative(base_url, target): 302 def make_relative(base_url, target):
304 if not target.startswith('/'): 303 if not target.startswith('/'):
305 # Links to an external resource 304 # Links to an external resource
306 return target 305 return target
307 return relpath(target, base_url.rsplit('/', 1)[0]) 306 return relpath(target, base_url.rsplit('/', 1)[0])
308 307
309 def process_link(match): 308 def process_link(match):
310 # if 'rel_path' in match.groups():
311 # import ipdb; ipdb.set_trace()
312 pre, attr, url, post = match.groups() 309 pre, attr, url, post = match.groups()
313 url = jinja2.Markup(url).unescape() 310 url = jinja2.Markup(url).unescape()
314 311
315 locale, new_url = ( 312 locale, new_url = (
316 self._params['source'] 313 self._params['source']
317 .resolve_link(url, self._params['locale'])) 314 .resolve_link(url, self._params['locale']))
318 315
319 if new_url is not None: 316 if new_url is not None:
320 url = new_url 317 url = new_url
321 if attr == 'href': 318 if attr == 'href':
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 'linkify': self.linkify, 437 'linkify': self.linkify,
441 'toclist': self.toclist, 438 'toclist': self.toclist,
442 } 439 }
443 440
444 globals = { 441 globals = {
445 'get_string': self.get_string, 442 'get_string': self.get_string,
446 'has_string': self.has_string, 443 'has_string': self.has_string,
447 'get_page_content': self.get_page_content, 444 'get_page_content': self.get_page_content,
448 'get_pages_metadata': self.get_pages_metadata, 445 'get_pages_metadata': self.get_pages_metadata,
449 'get_canonical_url': self.get_canonical_url, 446 'get_canonical_url': self.get_canonical_url,
450 'relative': self._params['relative'],
451 } 447 }
452 448
453 for dirname, dictionary in [('filters', filters), 449 for dirname, dictionary in [('filters', filters),
454 ('globals', globals)]: 450 ('globals', globals)]:
455 for filename in self._params['source'].list_files(dirname): 451 for filename in self._params['source'].list_files(dirname):
456 root, ext = os.path.splitext(filename) 452 root, ext = os.path.splitext(filename)
457 if ext.lower() != '.py': 453 if ext.lower() != '.py':
458 continue 454 continue
459 455
460 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
593 stack[-1]['subitems'].append(item) 589 stack[-1]['subitems'].append(item)
594 stack.append(item) 590 stack.append(item)
595 return structured 591 return structured
596 592
597 593
598 converters = { 594 converters = {
599 'html': RawConverter, 595 'html': RawConverter,
600 'md': MarkdownConverter, 596 'md': MarkdownConverter,
601 'tmpl': TemplateConverter, 597 'tmpl': TemplateConverter,
602 } 598 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld