aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/pluginapi.py
diff options
context:
space:
mode:
authorWill Kahn-Greene <willg@bluesock.org>2012-06-10 14:51:13 -0400
committerWill Kahn-Greene <willg@bluesock.org>2012-07-16 09:26:28 -0400
commit4bd65f69c710268404e1b1fdaac68db069558584 (patch)
treee812e6473a2a5b8011e657a1c2f8b6701cc1ab43 /mediagoblin/tools/pluginapi.py
parent8545dd50f0cd588d505c217d367450198199a2b0 (diff)
downloadmediagoblin-4bd65f69c710268404e1b1fdaac68db069558584.tar.lz
mediagoblin-4bd65f69c710268404e1b1fdaac68db069558584.tar.xz
mediagoblin-4bd65f69c710268404e1b1fdaac68db069558584.zip
Finish flatpagesplugin; add plugin docs
Diffstat (limited to 'mediagoblin/tools/pluginapi.py')
-rw-r--r--mediagoblin/tools/pluginapi.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/mediagoblin/tools/pluginapi.py b/mediagoblin/tools/pluginapi.py
index 1f5a9887..0c338540 100644
--- a/mediagoblin/tools/pluginapi.py
+++ b/mediagoblin/tools/pluginapi.py
@@ -80,6 +80,9 @@ class PluginCache(object):
# list of registered template paths
"template_paths": set(),
+
+ # list of registered routes
+ "routes": [],
}
def clear(self):
@@ -106,6 +109,13 @@ class PluginCache(object):
"""Returns a tuple of registered template paths"""
return tuple(self.template_paths)
+ def register_route(self, route):
+ """Registers a single route"""
+ self.routes.append(route)
+
+ def get_routes(self):
+ return tuple(self.routes)
+
class MetaPluginClass(type):
"""Metaclass for PluginBase derivatives"""
@@ -119,7 +129,7 @@ class MetaPluginClass(type):
class Plugin(object):
- """Exttend this class for plugins.
+ """Extend this class for plugins.
Example::
@@ -139,6 +149,44 @@ class Plugin(object):
pass
+def register_routes(routes):
+ """Registers one or more routes
+
+ If your plugin handles requests, then you need to call this with
+ the routes your plugin handles.
+
+ A "route" is a `routes.Route` object. See `the routes.Route
+ documentation
+ <http://routes.readthedocs.org/en/latest/modules/route.html>`_ for
+ more details.
+
+ Example passing in a single route:
+
+ >>> from routes import Route
+ >>> register_routes(Route('about-view', '/about',
+ ... controller=about_view_handler))
+
+ Example passing in a list of routes:
+
+ >>> from routes import Route
+ >>> register_routes([
+ ... Route('contact-view', '/contact', controller=contact_handler),
+ ... Route('about-view', '/about', controller=about_handler)
+ ... ])
+
+
+ .. Note::
+
+ Be careful when designing your route urls. If they clash with
+ core urls, then it could result in DISASTER!
+ """
+ if isinstance(routes, (tuple, list)):
+ for route in routes:
+ PluginCache().register_route(route)
+ else:
+ PluginCache().register_route(routes)
+
+
def register_template_path(path):
"""Registers a path for template loading