| OLD | NEW | 
|   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 process_page(source, locale, page, format, site_url_override=None): |  20 def process_page(source, locale, page, format, site_url_override=None): | 
|  21   params = { |  21   params = { | 
|  22     "source": source, |  22     "source": source, | 
|  23     "template": "default", |  23     "template": "default", | 
|  24     "locale": locale, |  24     "locale": locale, | 
|  25     "title": "title", |  | 
|  26     "page": page, |  25     "page": page, | 
|  27     "pagedata": source.read_page(page, format), |  26     "pagedata": source.read_page(page, format), | 
|  28     "config": source.read_config(), |  27     "config": source.read_config(), | 
|  29   } |  28   } | 
|  30  |  29  | 
|  31   localefile = page |  30   localefile = page | 
|  32   if params["config"].has_option("locale_overrides", page): |  31   if params["config"].has_option("locale_overrides", page): | 
|  33     localefile = params["config"].get("locale_overrides", page) |  32     localefile = params["config"].get("locale_overrides", page) | 
|  34   params["localedata"] = source.read_locale(params["locale"], localefile) |  33   params["localedata"] = source.read_locale(params["locale"], localefile) | 
|  35  |  34  | 
|  36   if params["config"].has_option("general", "siteurl"): |  35   if params["config"].has_option("general", "siteurl"): | 
|  37     if site_url_override: |  36     if site_url_override: | 
|  38       params["site_url"] = site_url_override |  37       params["site_url"] = site_url_override | 
|  39     else: |  38     else: | 
|  40       params["site_url"] = params["config"].get("general", "siteurl") |  39       params["site_url"] = params["config"].get("general", "siteurl") | 
|  41  |  40  | 
|  42   try: |  41   try: | 
|  43     converter = converters[format](params) |  42     converter = converters[format](params) | 
|  44   except KeyError: |  43   except KeyError: | 
|  45     raise Exception("Page %s uses unknown format %s" % (page, format)) |  44     raise Exception("Page %s uses unknown format %s" % (page, format)) | 
|  46  |  45  | 
|  47   # Note: The converter might change some parameters so we can only read in |  46   # Note: The converter might change some parameters so we can only read in | 
|  48   # template data here. |  47   # template data here. | 
|  49   params["templatedata"] = source.read_template(params["template"]) |  48   params["templatedata"] = source.read_template(params["template"]) | 
|  50   template_converter = TemplateConverter(params, key="templatedata") |  49   template_converter = TemplateConverter(params, key="templatedata") | 
|  51  |  50  | 
|  52   params["available_locales"] = sorted( |  51   defaultlocale = params["config"].get("general", "defaultlocale") | 
|  53     filter( |  52   params["defaultlocale"] = defaultlocale | 
|  54       lambda locale: source.has_locale(locale, localefile), |  53  | 
|  55       source.list_locales() |  54   locales = [ | 
|  56     ) |  55     locale | 
|  57   ) |  56     for locale in source.list_locales() | 
 |  57     if source.has_locale(locale, localefile) | 
 |  58   ] | 
 |  59   if defaultlocale not in locales: | 
 |  60     locales.append(defaultlocale) | 
 |  61   locales.sort() | 
 |  62   params["available_locales"] = locales | 
|  58  |  63  | 
|  59   params["head"], params["body"] = converter() |  64   params["head"], params["body"] = converter() | 
|  60   return template_converter() |  65   return template_converter() | 
| OLD | NEW |