From 02dde2d726817f117c7d366c43f9b784e2db4ba3 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 28 Jun 2010 12:09:58 +0200 Subject: [PATCH] proxy: Add a "proxy" theme that selects other themes based on the path. --- plugin/theme/proxy.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 plugin/theme/proxy.py diff --git a/plugin/theme/proxy.py b/plugin/theme/proxy.py new file mode 100644 index 0000000..58e4ab2 --- /dev/null +++ b/plugin/theme/proxy.py @@ -0,0 +1,42 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - Generic website theme. + + @copyright: 2009+ Matthijs Kooijman + @license: GNU GPL, see COPYING for details. + + This theme simply loads other themes, depending on the url requested. + + To use this theme, set the default theme to 'proxy' and set the + configuration value 'proxy_theme_mapping' to a list of (prefix, themename) + tuples (which will be tested in order, so be sure to include a theme with + an empty prefix at the end). For example: + + proxy_theme_mapping = [ + ('/Site/', 'deadfoxjunction'), + ('', 'modernized'), + ] + + The prefixes are matched against the page requested, so urls within + MoinMoin (and a trailing slash is included). + + This theme does not currently play well with user-selectable themes, since + that would completely bypass the proxy plugin. For now it is probably best + to set the theme_force configuration variable. +""" + +from MoinMoin.theme import load_theme, ThemeNotFound + +def Theme(context): + """ + Usually, a theme plugin defines a Theme class, whose constructor is + called. Instead, we define a Theme function that calls the proper + constructor. + """ + for (prefix, theme) in context.cfg.proxy_theme_mapping: + if context.request.path.startswith(prefix): + return load_theme(context, theme) + + raise ThemeNotFound("proxy_theme_mapping defines no theme for url: %s" % (context.request.path)) + +# vim: set sw=4 sts=4 expandtab: -- 2.30.2