diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-05-16 10:38:45 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-05-23 13:33:07 -0500 |
commit | d6d2c771bdc111cd26186b1bc42b44f2b3197e05 (patch) | |
tree | 2a046eea2ccf694ce71209c8b72d20deb9b51203 /mediagoblin | |
parent | 8ca51d32b66b96043c8685aac1e478111612c980 (diff) | |
download | mediagoblin-d6d2c771bdc111cd26186b1bc42b44f2b3197e05.tar.lz mediagoblin-d6d2c771bdc111cd26186b1bc42b44f2b3197e05.tar.xz mediagoblin-d6d2c771bdc111cd26186b1bc42b44f2b3197e05.zip |
Start of ability to have plugins provide static resources!
Note I have not tested any of this yet ;) But we're already on our way:
- We've got docs
- The hook is there
Lots to do still though. But, progress! :)
This commit sponsored by Laura Arjona Reina. Thanks larjona!
Diffstat (limited to 'mediagoblin')
-rw-r--r-- | mediagoblin/init/__init__.py | 7 | ||||
-rw-r--r-- | mediagoblin/tools/staticdirect.py | 38 |
2 files changed, 45 insertions, 0 deletions
diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py index d16027db..1eb9f1ba 100644 --- a/mediagoblin/init/__init__.py +++ b/mediagoblin/init/__init__.py @@ -24,6 +24,7 @@ from mediagoblin import mg_globals from mediagoblin.mg_globals import setup_globals from mediagoblin.db.open import setup_connection_and_db_from_config, \ check_db_migrations_current, load_models +from mediagoblin.pluginapi import hook_runall from mediagoblin.tools.workbench import WorkbenchManager from mediagoblin.storage import storage_system_from_config @@ -116,6 +117,12 @@ def get_staticdirector(app_config): direct_domains = {None: app_config['direct_remote_path'].strip()} direct_domains['theme'] = app_config['theme_web_path'].strip() + # Let plugins load additional paths + for plugin_static in hook_runall("static_setup"): + direct_domains[plugin_static['name']] = "%s/%s" % ( + app_config['plugin_web_path'].rstrip('/'), + plugin_static['name']) + return staticdirect.StaticDirect( direct_domains) diff --git a/mediagoblin/tools/staticdirect.py b/mediagoblin/tools/staticdirect.py index 31abc566..ef8b20d0 100644 --- a/mediagoblin/tools/staticdirect.py +++ b/mediagoblin/tools/staticdirect.py @@ -61,3 +61,41 @@ class StaticDirect(object): def get(self, filepath, domain=None): return '%s/%s' % ( self.domains[domain], filepath.lstrip('/')) + + +class PluginStatic(object): + """Pass this into the ``'static_setup'`` hook to register your + plugin's static directory. + + This has two mandatory attributes that you must pass in on class + init: + - name: this name will be both used for lookup in "urlgen" for + your plugin's static resources and for the subdirectory that + it'll be "mounted" to for serving via your web browser. It + *MUST* be unique. If writing a plugin bundled with MediaGoblin + please use the pattern 'coreplugin__foo' where 'foo' is your + plugin name. All external plugins should use their modulename, + so if your plugin is 'mg_bettertags' you should also call this + name 'mg_bettertags'. + - file_path: the directory your plugin's static resources are + located in. It's recommended that you use + pkg_resources.resource_filename() for this. + + An example of using this:: + + from pkg_resources import resource_filename + from mediagoblin.tools.staticdirect import PluginStatic + + hooks = { + 'static_setup': lambda: PluginStatic( + 'mg_bettertags', + resource_filename('mg_bettertags', 'static')) + } + + """ + def __init__(self, name, file_path): + self.name = name + self.file_path = file_path + + def __call__(self): + return self |