mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-26 15:28:37 -05:00
Build plugin JS in js.py.
This commit is contained in:
@@ -280,10 +280,19 @@ module["flot"] = Module("jquery.flot.js",
|
||||
def use(*names):
|
||||
return "\n".join(module[name].use() for name in names)
|
||||
|
||||
def load_plugin_modules():
|
||||
from r2.lib.plugin import PluginLoader
|
||||
for plugin in PluginLoader.available_plugins():
|
||||
plugin_cls = plugin.load()
|
||||
plugin_cls().add_js(module)
|
||||
|
||||
commands = {}
|
||||
def build_command(fn):
|
||||
commands[fn.__name__] = fn
|
||||
return fn
|
||||
def wrapped(*args):
|
||||
load_plugin_modules()
|
||||
fn(*args)
|
||||
commands[fn.__name__] = wrapped
|
||||
return wrapped
|
||||
|
||||
@build_command
|
||||
def enumerate_modules():
|
||||
|
||||
@@ -25,13 +25,16 @@ class Plugin(object):
|
||||
def on_load(self):
|
||||
pass
|
||||
|
||||
def add_js(self):
|
||||
from r2.lib import js
|
||||
def add_js(self, module_registry=None):
|
||||
if not module_registry:
|
||||
from r2.lib import js
|
||||
module_registry = js.module
|
||||
|
||||
for name, module in self.js.iteritems():
|
||||
if name not in js.module:
|
||||
js.module[name] = module
|
||||
if name not in module_registry:
|
||||
module_registry[name] = module
|
||||
else:
|
||||
js.module[name].extend(module)
|
||||
module_registry[name].extend(module)
|
||||
|
||||
def add_routes(self, mc):
|
||||
pass
|
||||
@@ -54,11 +57,15 @@ class PluginLoader(object):
|
||||
def __getitem__(self, key):
|
||||
return self.plugins[key]
|
||||
|
||||
@staticmethod
|
||||
def available_plugins(name=None):
|
||||
return pkg_resources.iter_entry_points('r2.plugin', name)
|
||||
|
||||
def load_plugins(self, plugin_names):
|
||||
g = config['pylons.g']
|
||||
for name in plugin_names:
|
||||
try:
|
||||
entry_point = pkg_resources.iter_entry_points('r2.plugin', name).next()
|
||||
entry_point = self.available_plugins(name).next()
|
||||
except StopIteration:
|
||||
g.log.warning('Unable to locate plugin "%s". Skipping.' % name)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user