diff options
author | Matthias Bartelmeß <mba@fourplusone.de> | 2012-04-04 15:03:28 +0200 |
---|---|---|
committer | Matthias Bartelmeß <mba@fourplusone.de> | 2012-04-04 15:03:28 +0200 |
commit | 5115f74f6679af7d7eda37873c92ae936e270df3 (patch) | |
tree | 80e04e08f090395e7d435aec8f81b44659723ead /src | |
parent | 49593a1c8ec2f5825f1e679ed0bb97ee821d5fda (diff) | |
download | etherpad-lite-5115f74f6679af7d7eda37873c92ae936e270df3.zip |
use hook name as function name, if not specified
Example `"[hookName]": "ep_plugin/static/js/index:[hookName]"` becomes `"[hookName]": "ep_plugin/static/js/index"`
Diffstat (limited to 'src')
-rw-r--r-- | src/static/js/pluginfw/plugins.js | 16 |
1 files 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]); } }); }); |