| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 | 2 |
| 3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
| 4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH |
| 5 # | 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
| 7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
| 8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
| 9 # | 9 # |
| 10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
| 14 # | 14 # |
| 15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
| 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 |
| 18 from .converters import converters, TemplateConverter | 18 from .converters import converters, TemplateConverter |
| 19 | 19 |
| 20 def get_page_params(source, locale, page, format=None, site_url_override=None): | 20 def get_page_params(source, locale, page, format=None, site_url_override=None): |
| 21 # Guess page format if omitted, but default to Markdown for friendlier excepti ons | 21 # Guess page format if omitted, but default to Markdown for friendlier excepti ons |
| 22 if format is None: | 22 if format is None: |
| 23 format = "md" | 23 for format in converters.iterkeys(): |
| 24 for fmt in converters.keys(): | 24 if source.has_page(page, format): |
| 25 if source.has_page(page, fmt): | 25 break |
| 26 format = fmt | 26 else: |
|
Sebastian Noack
2015/04/08 08:38:57
I'd prefer to break when we found a match. Then we
kzar
2015/04/08 08:50:20
Cool, I've never seen an `else` clause for a `for`
| |
| 27 format = "md" | |
| 27 | 28 |
| 28 params = { | 29 params = { |
| 29 "source": source, | 30 "source": source, |
| 30 "template": "default", | 31 "template": "default", |
| 31 "locale": locale, | 32 "locale": locale, |
| 32 "page": page, | 33 "page": page, |
| 33 "pagedata": source.read_page(page, format), | 34 "pagedata": source.read_page(page, format), |
| 34 "config": source.read_config(), | 35 "config": source.read_config(), |
| 35 } | 36 } |
| 36 | 37 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 params["available_locales"] = locales | 69 params["available_locales"] = locales |
| 69 | 70 |
| 70 params["head"], params["body"] = converter() | 71 params["head"], params["body"] = converter() |
| 71 return params | 72 return params |
| 72 | 73 |
| 73 def process_page(source, locale, page, format, site_url_override=None): | 74 def process_page(source, locale, page, format, site_url_override=None): |
| 74 return TemplateConverter( | 75 return TemplateConverter( |
| 75 get_page_params(source, locale, page, format, site_url_override), | 76 get_page_params(source, locale, page, format, site_url_override), |
| 76 key="templatedata" | 77 key="templatedata" |
| 77 )() | 78 )() |
| LEFT | RIGHT |