From f0f7989299b67e12cbc80eea3d887b311dc293a7 Mon Sep 17 00:00:00 2001 From: Max Goodman Date: Thu, 9 Feb 2012 14:22:07 -0800 Subject: [PATCH] Allow plugins to add and extend js modules. --- r2/r2/lib/js.py | 5 ++++- r2/r2/lib/plugin.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/r2/r2/lib/js.py b/r2/r2/lib/js.py index 9ac4039f0..0226440b1 100755 --- a/r2/r2/lib/js.py +++ b/r2/r2/lib/js.py @@ -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.""" diff --git a/r2/r2/lib/plugin.py b/r2/r2/lib/plugin.py index 706caaa72..d5a047760 100644 --- a/r2/r2/lib/plugin.py +++ b/r2/r2/lib/plugin.py @@ -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):