diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 9209967ce..f284e4783 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -6,6 +6,7 @@ var settings = require("../../utils/Settings"); var Yajsml = require('yajsml'); var fs = require("fs"); var ERR = require("async-stacktrace"); +var _ = require("underscore"); exports.expressCreateServer = function (hook_name, args, cb) { // Cache both minified and static. @@ -35,8 +36,22 @@ exports.expressCreateServer = function (hook_name, args, cb) { // serve plugin definitions // not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js"); args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) { + + var clientParts = _(plugins.parts) + .filter(function(part){ return _(part).has('client_hooks') }); + + var clientPlugins = {}; + + _(clientParts).chain() + .map(function(part){ return part.plugin }) + .uniq() + .each(function(name){ + clientPlugins[name] = _(plugins.plugins[name]).clone(); + delete clientPlugins[name]['package']; + }); + res.header("Content-Type","application/json; charset=utf-8"); - res.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts})); + res.write(JSON.stringify({"plugins": clientPlugins, "parts": clientParts})); res.end(); }); } diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index 1cf1023e2..db0b92e49 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -50,10 +50,12 @@ exports.formatHooks = function () { return res.join("\n"); }; -exports.loadFn = function (path) { +exports.loadFn = function (path, hookName) { var x = path.split(":"); var fn = require(x[0]); - _.each(x[1].split("."), function (name) { + var functionName = x[1] ? x[1] : hookName; + + _.each(functionName.split("."), function (name) { fn = fn[name]; }); return fn; @@ -62,10 +64,14 @@ exports.loadFn = function (path) { exports.extractHooks = function (parts, hook_set_name) { var hooks = {}; _.each(parts,function (part) { - _.chain(part[hook_set_name] || {}).keys().each(function (hook_name) { + _.chain(part[hook_set_name] || {}) + .keys() + .each(function (hook_name) { if (hooks[hook_name] === undefined) hooks[hook_name] = []; + + var hook_fn_name = part[hook_set_name][hook_name]; - var hook_fn = exports.loadFn(part[hook_set_name][hook_name]); + var hook_fn = exports.loadFn(hook_fn_name, hook_name); if (hook_fn) { hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part}); } else {