From 5115f74f6679af7d7eda37873c92ae936e270df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Wed, 4 Apr 2012 15:03:28 +0200 Subject: [PATCH 1/2] use hook name as function name, if not specified Example `"[hookName]": "ep_plugin/static/js/index:[hookName]"` becomes `"[hookName]": "ep_plugin/static/js/index"` --- src/static/js/pluginfw/plugins.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index 058f1351..b56c0dd9 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -51,10 +51,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; @@ -63,14 +65,18 @@ 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 { - console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]); + console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]); } }); }); From f34e13f761646bf75d7f41a4d8958bb6033a48a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Wed, 4 Apr 2012 15:10:27 +0200 Subject: [PATCH 2/2] on plugin definitions, only expose plugins with client_hooks registered. dont expose 'package' property --- src/node/hooks/express/static.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 9209967c..f284e478 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(); }); }