mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-20 06:29:53 +01:00
use hook name as function name, if not specified
Example `"[hookName]": "ep_plugin/static/js/index:[hookName]"` becomes `"[hookName]": "ep_plugin/static/js/index"`
This commit is contained in:
parent
49593a1c8e
commit
5115f74f66
1 changed files with 11 additions and 5 deletions
|
@ -51,10 +51,12 @@ exports.formatHooks = function () {
|
||||||
return res.join("\n");
|
return res.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.loadFn = function (path) {
|
exports.loadFn = function (path, hookName) {
|
||||||
var x = path.split(":");
|
var x = path.split(":");
|
||||||
var fn = require(x[0]);
|
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];
|
fn = fn[name];
|
||||||
});
|
});
|
||||||
return fn;
|
return fn;
|
||||||
|
@ -63,10 +65,14 @@ exports.loadFn = function (path) {
|
||||||
exports.extractHooks = function (parts, hook_set_name) {
|
exports.extractHooks = function (parts, hook_set_name) {
|
||||||
var hooks = {};
|
var hooks = {};
|
||||||
_.each(parts,function (part) {
|
_.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] = [];
|
if (hooks[hook_name] === undefined) hooks[hook_name] = [];
|
||||||
|
|
||||||
|
|
||||||
var hook_fn_name = part[hook_set_name][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) {
|
if (hook_fn) {
|
||||||
hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
|
hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue