58e4ab2d89fb47f7059603bbb43356f8b3459d36
[matthijs/projects/wipi.git] / plugin / theme / proxy.py
1 # -*- coding: iso-8859-1 -*-
2 """
3     MoinMoin - Generic website theme.
4
5     @copyright: 2009+ Matthijs Kooijman
6     @license: GNU GPL, see COPYING for details.
7
8     This theme simply loads other themes, depending on the url requested.
9
10     To use this theme, set the default theme to 'proxy' and set the
11     configuration value 'proxy_theme_mapping' to a list of (prefix, themename)
12     tuples (which will be tested in order, so be sure to include a theme with
13     an empty prefix at the end). For example:
14
15         proxy_theme_mapping = [
16             ('/Site/', 'deadfoxjunction'),
17             ('', 'modernized'),
18         ]
19
20     The prefixes are matched against the page requested, so urls within
21     MoinMoin (and a trailing slash is included).
22
23     This theme does not currently play well with user-selectable themes, since
24     that would completely bypass the proxy plugin. For now it is probably best
25     to set the theme_force configuration variable.
26 """
27
28 from MoinMoin.theme import load_theme, ThemeNotFound
29
30 def Theme(context):
31     """
32     Usually, a theme plugin defines a Theme class, whose constructor is
33     called.  Instead, we define a Theme function that calls the proper
34     constructor.
35     """
36     for (prefix, theme) in context.cfg.proxy_theme_mapping:
37         if context.request.path.startswith(prefix):
38             return load_theme(context, theme)
39
40     raise ThemeNotFound("proxy_theme_mapping defines no theme for url: %s" % (context.request.path))
41
42 # vim: set sw=4 sts=4 expandtab: