Allow plugins to add and extend js modules.

This commit is contained in:
Max Goodman
2012-02-09 14:22:07 -08:00
parent aaf751ab48
commit f0f7989299
2 changed files with 15 additions and 1 deletions

View File

@@ -99,7 +99,10 @@ class Module(Source):
def get_source(self):
return ";".join(s.get_source() for s in self.sources)
def extend(self, module):
self.sources.extend(module.sources)
@property
def path(self):
"""The destination path of the module file on the filesystem."""

View File

@@ -5,6 +5,8 @@ from pylons import config
class Plugin(object):
js = {}
@property
def path(self):
module = sys.modules[type(self).__module__]
@@ -19,6 +21,14 @@ class Plugin(object):
def static_dir(self):
return os.path.join(self.path, 'public')
def add_js(self):
from r2.lib import js
for name, module in self.js.iteritems():
if name not in js.module:
js.module[name] = module
else:
js.module[name].extend(module)
def add_routes(self, mc):
pass
@@ -50,6 +60,7 @@ class PluginLoader(object):
plugin_cls = entry_point.load()
plugin = self.plugins[name] = plugin_cls()
config['pylons.paths']['templates'].extend(plugin.template_dirs)
plugin.add_js()
return self
def load_controllers(self):