Index: sitescripts/web/utils.py |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/sitescripts/web/utils.py |
@@ -0,0 +1,51 @@ |
+# coding: utf-8 |
+ |
+# This file is part of the Adblock Plus web scripts, |
+# Copyright (C) 2006-2013 Eyeo GmbH |
+# |
+# Adblock Plus is free software: you can redistribute it and/or modify |
+# it under the terms of the GNU General Public License version 3 as |
+# published by the Free Software Foundation. |
+# |
+# Adblock Plus is distributed in the hope that it will be useful, |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+# GNU General Public License for more details. |
+# |
+# You should have received a copy of the GNU General Public License |
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ |
+from sitescripts.web.converters import converters, TemplateConverter |
+ |
+def process_page(source, locale, page, format): |
+ params = { |
+ "source": source, |
+ "template": "default", |
+ "locale": locale, |
+ "title": "title", |
+ "page": page, |
+ "pagedata": source.read_page(page, format), |
+ "toc": True, |
+ "config": source.read_config(), |
+ } |
+ |
+ try: |
+ converter = converters[format](params) |
+ except KeyError: |
+ raise Exception("Page %s uses unknown format %s" % (page, format)) |
+ |
+ # Note: The converter might change some parameters so we can only read in |
+ # template and locale data here. |
+ params["templatedata"] = source.read_template(params["template"]) |
+ params["localedata"] = source.read_locale(params["locale"], params["page"]) |
+ template_converter = TemplateConverter(params, key="templatedata") |
+ |
+ params["available_locales"] = sorted( |
+ filter( |
+ lambda locale: source.has_locale(locale, params["page"]), |
+ source.list_locales() |
+ ) |
+ ) |
+ |
+ params["head"], params["body"] = map(lambda s: s.decode("utf-8"), converter()) |
+ return template_converter() |