aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/pluginapi.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tools/pluginapi.py')
-rw-r--r--mediagoblin/tools/pluginapi.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/mediagoblin/tools/pluginapi.py b/mediagoblin/tools/pluginapi.py
index 38ab631b..2b8e95f4 100644
--- a/mediagoblin/tools/pluginapi.py
+++ b/mediagoblin/tools/pluginapi.py
@@ -83,6 +83,9 @@ class PluginManager(object):
# list of registered template paths
"template_paths": set(),
+ # list of template hooks
+ "template_hooks": {},
+
# list of registered routes
"routes": [],
}
@@ -131,6 +134,28 @@ class PluginManager(object):
def get_routes(self):
return tuple(self.routes)
+ def register_template_hooks(self, template_hooks):
+ """
+ Register a dict of template hooks.
+
+ Takes template_hooks as an argument, which is a dictionary of
+ template hook names/keys to the templates they should provide.
+ (The value can either be a single template path or an iterable
+ of paths.)
+
+ Example:
+ {"media_sidebar": "/plugin/sidemess/mess_up_the_side.html",
+ "media_descriptionbox": ["/plugin/sidemess/even_more_mess.html",
+ "/plugin/sidemess/so_much_mess.html"]}
+ """
+ for hook, templates in template_hooks.items():
+ if isinstance(templates, (list, tuple)):
+ self.template_hooks.setdefault(hook, []).extend(list(templates))
+ else:
+ # In this case, it's actually a single callable---not a
+ # list of callables.
+ self.hooks.setdefault(hook, []).append(templates)
+
def register_routes(routes):
"""Registers one or more routes
@@ -208,3 +233,5 @@ def get_config(key):
return plugin_section.get(key, {})
+def register_template_hooks(template_hooks):
+ PluginManager().register_template_hooks(template_hooks)