diff options
Diffstat (limited to 'mediagoblin/tools')
-rw-r--r-- | mediagoblin/tools/pluginapi.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/mediagoblin/tools/pluginapi.py b/mediagoblin/tools/pluginapi.py index 74d05def..1f5a9887 100644 --- a/mediagoblin/tools/pluginapi.py +++ b/mediagoblin/tools/pluginapi.py @@ -76,7 +76,10 @@ class PluginCache(object): "plugin_classes": [], # list of plugin objects - "plugin_objects": [] + "plugin_objects": [], + + # list of registered template paths + "template_paths": set(), } def clear(self): @@ -95,6 +98,14 @@ class PluginCache(object): """Registers a plugin object""" self.plugin_objects.append(plugin_obj) + def register_template_path(self, path): + """Registers a template path""" + self.template_paths.add(path) + + def get_template_paths(self): + """Returns a tuple of registered template paths""" + return tuple(self.template_paths) + class MetaPluginClass(type): """Metaclass for PluginBase derivatives""" @@ -128,6 +139,27 @@ class Plugin(object): pass +def register_template_path(path): + """Registers a path for template loading + + If your plugin has templates, then you need to call this with + the absolute path of the root of templates directory. + + Example: + + >>> my_plugin_dir = os.path.dirname(__file__) + >>> template_dir = os.path.join(my_plugin_dir, 'templates') + >>> register_template_path(template_dir) + + .. Note:: + + You can only do this in `setup_plugins()`. Doing this after + that will have no effect on template loading. + + """ + PluginCache().register_template_path(path) + + def get_config(key): """Retrieves the configuration for a specified plugin by key |