mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 15:58:06 -05:00
Allow plugins to add and extend js modules.
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user