aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/pluginapi.py
diff options
context:
space:
mode:
authorWill Kahn-Greene <willg@bluesock.org>2012-06-10 11:50:14 -0400
committerWill Kahn-Greene <willg@bluesock.org>2012-07-16 09:26:28 -0400
commit8545dd50f0cd588d505c217d367450198199a2b0 (patch)
tree3ba262185cbbf7366f1ab9673efd49d1c6856fe0 /mediagoblin/tools/pluginapi.py
parent62157a898f60fab7c82eb76b2969354f9f02390d (diff)
downloadmediagoblin-8545dd50f0cd588d505c217d367450198199a2b0.tar.lz
mediagoblin-8545dd50f0cd588d505c217d367450198199a2b0.tar.xz
mediagoblin-8545dd50f0cd588d505c217d367450198199a2b0.zip
Flatpages first pass
This fixes the template loader so that it can load plugin templates. This adds code for registering template paths so that plugins can add their own templates. This adds the base code for the flatpagesfile plugin. It doesn't serve pages, yet, but it's pretty close.
Diffstat (limited to 'mediagoblin/tools/pluginapi.py')
-rw-r--r--mediagoblin/tools/pluginapi.py34
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