Rework plugin infrastructure to nix side-effects
This reworks the plugin infrastructure so as to remove module-loading side-effects which were making things a pain in the ass to test. With the new system, there's no auto-registering meta class. Instead plugins do whatever they want and then specify a hooks dict that maps hook names to callables for the things they're tying into. The most common one (and the only one we've implemented so far) is "setup". This also simplifies the sampleplugin a little by moving the code to __init__.py.
This commit is contained in:
@@ -53,27 +53,27 @@ def flatpage_handler_builder(template):
|
||||
return _flatpage_handler_builder
|
||||
|
||||
|
||||
class FlatpagesFilePlugin(pluginapi.Plugin):
|
||||
"""
|
||||
This is the flatpages plugin class. See the README for how to use
|
||||
flatpages.
|
||||
"""
|
||||
def setup_plugin(self):
|
||||
self.config = pluginapi.get_config('mediagoblin.plugins.flatpagesfile')
|
||||
def setup_plugin():
|
||||
config = pluginapi.get_config('mediagoblin.plugins.flatpagesfile')
|
||||
|
||||
_log.info('Setting up flatpagesfile....')
|
||||
_log.info('Setting up flatpagesfile....')
|
||||
|
||||
# Register the template path.
|
||||
pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates'))
|
||||
# Register the template path.
|
||||
pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates'))
|
||||
|
||||
pages = self.config.items()
|
||||
pages = config.items()
|
||||
|
||||
routes = []
|
||||
for name, (url, template) in pages:
|
||||
name = 'flatpagesfile.%s' % name.strip()
|
||||
controller = flatpage_handler_builder(template)
|
||||
routes.append(
|
||||
Route(name, url, controller=controller))
|
||||
routes = []
|
||||
for name, (url, template) in pages:
|
||||
name = 'flatpagesfile.%s' % name.strip()
|
||||
controller = flatpage_handler_builder(template)
|
||||
routes.append(
|
||||
Route(name, url, controller=controller))
|
||||
|
||||
pluginapi.register_routes(routes)
|
||||
_log.info('Done setting up flatpagesfile!')
|
||||
pluginapi.register_routes(routes)
|
||||
_log.info('Done setting up flatpagesfile!')
|
||||
|
||||
|
||||
hooks = {
|
||||
'setup': setup_plugin
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user