commit
389e0d09b0
|
@ -29,6 +29,7 @@ var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||||
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
||||||
var npm = require("npm/lib/npm.js");
|
var npm = require("npm/lib/npm.js");
|
||||||
|
|
||||||
|
hooks.plugins = plugins;
|
||||||
|
|
||||||
//set loglevel
|
//set loglevel
|
||||||
log4js.setGlobalLogLevel(settings.loglevel);
|
log4js.setGlobalLogLevel(settings.loglevel);
|
||||||
|
|
|
@ -68,7 +68,8 @@
|
||||||
, "security.js"
|
, "security.js"
|
||||||
, "$security.js"
|
, "$security.js"
|
||||||
, "json2.js"
|
, "json2.js"
|
||||||
, "pluginfw/plugins.js"
|
, "pluginfw/client_plugins.js"
|
||||||
|
, "pluginfw/shared.js"
|
||||||
, "pluginfw/hooks.js"
|
, "pluginfw/hooks.js"
|
||||||
, "pluginfw/parent_require.js"
|
, "pluginfw/parent_require.js"
|
||||||
]
|
]
|
||||||
|
|
|
@ -244,7 +244,7 @@ require.setGlobalKeyPath("require");\n\
|
||||||
<script type="text/javascript">\
|
<script type="text/javascript">\
|
||||||
parent_req = require("ep_etherpad-lite/static/js/pluginfw/parent_require");\
|
parent_req = require("ep_etherpad-lite/static/js/pluginfw/parent_require");\
|
||||||
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/hooks");\
|
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/hooks");\
|
||||||
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/plugins");\
|
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/client_plugins");\
|
||||||
</script>\
|
</script>\
|
||||||
');
|
');
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ var editor, _, $, jQuery, plugins, Ace2Common;
|
||||||
|
|
||||||
Ace2Common = require('./ace2_common');
|
Ace2Common = require('./ace2_common');
|
||||||
|
|
||||||
plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
|
plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
|
||||||
$ = jQuery = require('./rjquery').$;
|
$ = jQuery = require('./rjquery').$;
|
||||||
_ = require("./underscore");
|
_ = require("./underscore");
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
var $, jQuery;
|
||||||
|
$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
|
||||||
|
var _ = require("underscore");
|
||||||
|
|
||||||
|
var pluginUtils = require('./shared');
|
||||||
|
|
||||||
|
exports.loaded = false;
|
||||||
|
exports.plugins = {};
|
||||||
|
exports.parts = [];
|
||||||
|
exports.hooks = {};
|
||||||
|
exports.baseURL = '';
|
||||||
|
|
||||||
|
exports.ensure = function (cb) {
|
||||||
|
if (!exports.loaded)
|
||||||
|
exports.update(cb);
|
||||||
|
else
|
||||||
|
cb();
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.update = function (cb) {
|
||||||
|
// It appears that this response (see #620) may interrupt the current thread
|
||||||
|
// of execution on Firefox. This schedules the response in the run-loop,
|
||||||
|
// which appears to fix the issue.
|
||||||
|
var callback = function () {setTimeout(cb, 0);};
|
||||||
|
|
||||||
|
jQuery.getJSON(exports.baseURL + 'pluginfw/plugin-definitions.json', function(data) {
|
||||||
|
exports.plugins = data.plugins;
|
||||||
|
exports.parts = data.parts;
|
||||||
|
exports.hooks = pluginUtils.extractHooks(exports.parts, "client_hooks");
|
||||||
|
exports.loaded = true;
|
||||||
|
callback();
|
||||||
|
}).error(function(xhr, s, err){
|
||||||
|
console.error("Failed to load plugin-definitions: " + err);
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
};
|
|
@ -1,4 +1,3 @@
|
||||||
var plugins = require("./plugins");
|
|
||||||
var async = require("async");
|
var async = require("async");
|
||||||
var _ = require("underscore");
|
var _ = require("underscore");
|
||||||
|
|
||||||
|
@ -71,8 +70,8 @@ exports.flatten = function (lst) {
|
||||||
|
|
||||||
exports.callAll = function (hook_name, args) {
|
exports.callAll = function (hook_name, args) {
|
||||||
if (!args) args = {};
|
if (!args) args = {};
|
||||||
if (plugins.hooks[hook_name] === undefined) return [];
|
if (exports.plugins.hooks[hook_name] === undefined) return [];
|
||||||
return _.flatten(_.map(plugins.hooks[hook_name], function (hook) {
|
return _.flatten(_.map(exports.plugins.hooks[hook_name], function (hook) {
|
||||||
return hookCallWrapper(hook, hook_name, args);
|
return hookCallWrapper(hook, hook_name, args);
|
||||||
}), true);
|
}), true);
|
||||||
}
|
}
|
||||||
|
@ -80,9 +79,9 @@ exports.callAll = function (hook_name, args) {
|
||||||
exports.aCallAll = function (hook_name, args, cb) {
|
exports.aCallAll = function (hook_name, args, cb) {
|
||||||
if (!args) args = {};
|
if (!args) args = {};
|
||||||
if (!cb) cb = function () {};
|
if (!cb) cb = function () {};
|
||||||
if (plugins.hooks[hook_name] === undefined) return cb(null, []);
|
if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []);
|
||||||
async.map(
|
async.map(
|
||||||
plugins.hooks[hook_name],
|
exports.plugins.hooks[hook_name],
|
||||||
function (hook, cb) {
|
function (hook, cb) {
|
||||||
hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); });
|
hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); });
|
||||||
},
|
},
|
||||||
|
@ -94,8 +93,8 @@ exports.aCallAll = function (hook_name, args, cb) {
|
||||||
|
|
||||||
exports.callFirst = function (hook_name, args) {
|
exports.callFirst = function (hook_name, args) {
|
||||||
if (!args) args = {};
|
if (!args) args = {};
|
||||||
if (plugins.hooks[hook_name] === undefined) return [];
|
if (exports.plugins.hooks[hook_name] === undefined) return [];
|
||||||
return exports.syncMapFirst(plugins.hooks[hook_name], function (hook) {
|
return exports.syncMapFirst(exports.plugins.hooks[hook_name], function (hook) {
|
||||||
return hookCallWrapper(hook, hook_name, args);
|
return hookCallWrapper(hook, hook_name, args);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -103,9 +102,9 @@ exports.callFirst = function (hook_name, args) {
|
||||||
exports.aCallFirst = function (hook_name, args, cb) {
|
exports.aCallFirst = function (hook_name, args, cb) {
|
||||||
if (!args) args = {};
|
if (!args) args = {};
|
||||||
if (!cb) cb = function () {};
|
if (!cb) cb = function () {};
|
||||||
if (plugins.hooks[hook_name] === undefined) return cb(null, []);
|
if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []);
|
||||||
exports.mapFirst(
|
exports.mapFirst(
|
||||||
plugins.hooks[hook_name],
|
exports.plugins.hooks[hook_name],
|
||||||
function (hook, cb) {
|
function (hook, cb) {
|
||||||
hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); });
|
hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); });
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,30 +1,21 @@
|
||||||
exports.isClient = typeof global != "object";
|
var npm = require("npm/lib/npm.js");
|
||||||
|
var readInstalled = require("./read-installed.js");
|
||||||
|
var relativize = require("npm/lib/utils/relativize.js");
|
||||||
|
var readJson = require("npm/lib/utils/read-json.js");
|
||||||
|
var path = require("path");
|
||||||
|
var async = require("async");
|
||||||
|
var fs = require("fs");
|
||||||
|
var tsort = require("./tsort");
|
||||||
|
var util = require("util");
|
||||||
|
var _ = require("underscore");
|
||||||
|
|
||||||
var _;
|
var pluginUtils = require('./shared');
|
||||||
|
|
||||||
if (!exports.isClient) {
|
|
||||||
var npm = require("npm/lib/npm.js");
|
|
||||||
var readInstalled = require("./read-installed.js");
|
|
||||||
var relativize = require("npm/lib/utils/relativize.js");
|
|
||||||
var readJson = require("npm/lib/utils/read-json.js");
|
|
||||||
var path = require("path");
|
|
||||||
var async = require("async");
|
|
||||||
var fs = require("fs");
|
|
||||||
var tsort = require("./tsort");
|
|
||||||
var util = require("util");
|
|
||||||
_ = require("underscore");
|
|
||||||
}else{
|
|
||||||
var $, jQuery;
|
|
||||||
$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
|
|
||||||
_ = require("ep_etherpad-lite/static/js/underscore");
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.prefix = 'ep_';
|
exports.prefix = 'ep_';
|
||||||
exports.loaded = false;
|
exports.loaded = false;
|
||||||
exports.plugins = {};
|
exports.plugins = {};
|
||||||
exports.parts = [];
|
exports.parts = [];
|
||||||
exports.hooks = {};
|
exports.hooks = {};
|
||||||
exports.baseURL = '';
|
|
||||||
|
|
||||||
exports.ensure = function (cb) {
|
exports.ensure = function (cb) {
|
||||||
if (!exports.loaded)
|
if (!exports.loaded)
|
||||||
|
@ -43,7 +34,7 @@ exports.formatParts = function () {
|
||||||
|
|
||||||
exports.formatHooks = function (hook_set_name) {
|
exports.formatHooks = function (hook_set_name) {
|
||||||
var res = [];
|
var res = [];
|
||||||
var hooks = exports.extractHooks(exports.parts, hook_set_name || "hooks");
|
var hooks = pluginUtils.extractHooks(exports.parts, hook_set_name || "hooks");
|
||||||
|
|
||||||
_.chain(hooks).keys().forEach(function (hook_name) {
|
_.chain(hooks).keys().forEach(function (hook_name) {
|
||||||
_.forEach(hooks[hook_name], function (hook) {
|
_.forEach(hooks[hook_name], function (hook) {
|
||||||
|
@ -53,84 +44,6 @@ exports.formatHooks = function (hook_set_name) {
|
||||||
return "<dl>" + res.join("\n") + "</dl>";
|
return "<dl>" + res.join("\n") + "</dl>";
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.loadFn = function (path, hookName) {
|
|
||||||
var functionName
|
|
||||||
, parts = path.split(":");
|
|
||||||
|
|
||||||
// on windows: C:\foo\bar:xyz
|
|
||||||
if(parts[0].length == 1) {
|
|
||||||
if(parts.length == 3)
|
|
||||||
functionName = parts.pop();
|
|
||||||
path = parts.join(":");
|
|
||||||
}else{
|
|
||||||
path = parts[0];
|
|
||||||
functionName = parts[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
var fn = require(path);
|
|
||||||
functionName = functionName ? functionName : hookName;
|
|
||||||
|
|
||||||
_.each(functionName.split("."), function (name) {
|
|
||||||
fn = fn[name];
|
|
||||||
});
|
|
||||||
return fn;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.extractHooks = function (parts, hook_set_name) {
|
|
||||||
var hooks = {};
|
|
||||||
_.each(parts,function (part) {
|
|
||||||
_.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];
|
|
||||||
|
|
||||||
/* On the server side, you can't just
|
|
||||||
* require("pluginname/whatever") if the plugin is installed as
|
|
||||||
* a dependency of another plugin! Bah, pesky little details of
|
|
||||||
* npm... */
|
|
||||||
if (!exports.isClient) {
|
|
||||||
hook_fn_name = path.normalize(path.join(path.dirname(exports.plugins[part.plugin].package.path), hook_fn_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
var hook_fn = exports.loadFn(hook_fn_name, hook_name);
|
|
||||||
if (!hook_fn) {
|
|
||||||
throw "Not a function";
|
|
||||||
}
|
|
||||||
} catch (exc) {
|
|
||||||
console.error("Failed to load '" + hook_fn_name + "' for '" + part.full_name + "/" + hook_set_name + "/" + hook_name + "': " + exc.toString())
|
|
||||||
}
|
|
||||||
if (hook_fn) {
|
|
||||||
hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return hooks;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if (exports.isClient) {
|
|
||||||
exports.update = function (cb) {
|
|
||||||
// It appears that this response (see #620) may interrupt the current thread
|
|
||||||
// of execution on Firefox. This schedules the response in the run-loop,
|
|
||||||
// which appears to fix the issue.
|
|
||||||
var callback = function () {setTimeout(cb, 0);};
|
|
||||||
|
|
||||||
jQuery.getJSON(exports.baseURL + 'pluginfw/plugin-definitions.json', function(data) {
|
|
||||||
exports.plugins = data.plugins;
|
|
||||||
exports.parts = data.parts;
|
|
||||||
exports.hooks = exports.extractHooks(exports.parts, "client_hooks");
|
|
||||||
exports.loaded = true;
|
|
||||||
callback();
|
|
||||||
}).error(function(xhr, s, err){
|
|
||||||
console.error("Failed to load plugin-definitions: " + err);
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
|
|
||||||
exports.callInit = function (cb) {
|
exports.callInit = function (cb) {
|
||||||
var hooks = require("./hooks");
|
var hooks = require("./hooks");
|
||||||
async.map(
|
async.map(
|
||||||
|
@ -153,6 +66,10 @@ exports.callInit = function (cb) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.pathNormalization = function (part, hook_fn_name) {
|
||||||
|
return path.normalize(path.join(path.dirname(exports.plugins[part.plugin].package.path), hook_fn_name));
|
||||||
|
}
|
||||||
|
|
||||||
exports.update = function (cb) {
|
exports.update = function (cb) {
|
||||||
exports.getPackages(function (er, packages) {
|
exports.getPackages(function (er, packages) {
|
||||||
var parts = [];
|
var parts = [];
|
||||||
|
@ -161,13 +78,13 @@ exports.update = function (cb) {
|
||||||
async.forEach(
|
async.forEach(
|
||||||
Object.keys(packages),
|
Object.keys(packages),
|
||||||
function (plugin_name, cb) {
|
function (plugin_name, cb) {
|
||||||
exports.loadPlugin(packages, plugin_name, plugins, parts, cb);
|
loadPlugin(packages, plugin_name, plugins, parts, cb);
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
if (err) cb(err);
|
if (err) cb(err);
|
||||||
exports.plugins = plugins;
|
exports.plugins = plugins;
|
||||||
exports.parts = exports.sortParts(parts);
|
exports.parts = sortParts(parts);
|
||||||
exports.hooks = exports.extractHooks(exports.parts, "hooks");
|
exports.hooks = pluginUtils.extractHooks(exports.parts, "hooks", exports.pathNormalization);
|
||||||
exports.loaded = true;
|
exports.loaded = true;
|
||||||
exports.callInit(cb);
|
exports.callInit(cb);
|
||||||
}
|
}
|
||||||
|
@ -200,9 +117,9 @@ exports.getPackages = function (cb) {
|
||||||
flatten(tmp);
|
flatten(tmp);
|
||||||
cb(null, packages);
|
cb(null, packages);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.loadPlugin = function (packages, plugin_name, plugins, parts, cb) {
|
function loadPlugin(packages, plugin_name, plugins, parts, cb) {
|
||||||
var plugin_path = path.resolve(packages[plugin_name].path, "ep.json");
|
var plugin_path = path.resolve(packages[plugin_name].path, "ep.json");
|
||||||
fs.readFile(
|
fs.readFile(
|
||||||
plugin_path,
|
plugin_path,
|
||||||
|
@ -226,9 +143,9 @@ exports.getPackages = function (cb) {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.partsToParentChildList = function (parts) {
|
function partsToParentChildList(parts) {
|
||||||
var res = [];
|
var res = [];
|
||||||
_.chain(parts).keys().forEach(function (name) {
|
_.chain(parts).keys().forEach(function (name) {
|
||||||
_.each(parts[name].post || [], function (child_name) {
|
_.each(parts[name].post || [], function (child_name) {
|
||||||
|
@ -242,18 +159,15 @@ exports.partsToParentChildList = function (parts) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// Used only in Node, so no need for _
|
// Used only in Node, so no need for _
|
||||||
exports.sortParts = function(parts) {
|
function sortParts(parts) {
|
||||||
return tsort(
|
return tsort(
|
||||||
exports.partsToParentChildList(parts)
|
partsToParentChildList(parts)
|
||||||
).filter(
|
).filter(
|
||||||
function (name) { return parts[name] !== undefined; }
|
function (name) { return parts[name] !== undefined; }
|
||||||
).map(
|
).map(
|
||||||
function (name) { return parts[name]; }
|
function (name) { return parts[name]; }
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
var _ = require("underscore");
|
||||||
|
|
||||||
|
function loadFn(path, hookName) {
|
||||||
|
var functionName
|
||||||
|
, parts = path.split(":");
|
||||||
|
|
||||||
|
// on windows: C:\foo\bar:xyz
|
||||||
|
if (parts[0].length == 1) {
|
||||||
|
if (parts.length == 3) {
|
||||||
|
functionName = parts.pop();
|
||||||
|
}
|
||||||
|
path = parts.join(":");
|
||||||
|
} else {
|
||||||
|
path = parts[0];
|
||||||
|
functionName = parts[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
var fn = require(path);
|
||||||
|
functionName = functionName ? functionName : hookName;
|
||||||
|
|
||||||
|
_.each(functionName.split("."), function (name) {
|
||||||
|
fn = fn[name];
|
||||||
|
});
|
||||||
|
return fn;
|
||||||
|
};
|
||||||
|
|
||||||
|
function extractHooks(parts, hook_set_name, normalizer) {
|
||||||
|
var hooks = {};
|
||||||
|
_.each(parts,function (part) {
|
||||||
|
_.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];
|
||||||
|
|
||||||
|
/* On the server side, you can't just
|
||||||
|
* require("pluginname/whatever") if the plugin is installed as
|
||||||
|
* a dependency of another plugin! Bah, pesky little details of
|
||||||
|
* npm... */
|
||||||
|
if (normalizer) {
|
||||||
|
hook_fn_name = normalizer(part, hook_fn_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
var hook_fn = loadFn(hook_fn_name, hook_name);
|
||||||
|
if (!hook_fn) {
|
||||||
|
throw "Not a function";
|
||||||
|
}
|
||||||
|
} catch (exc) {
|
||||||
|
console.error("Failed to load '" + hook_fn_name + "' for '" + part.full_name + "/" + hook_set_name + "/" + hook_name + "': " + exc.toString())
|
||||||
|
}
|
||||||
|
if (hook_fn) {
|
||||||
|
hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return hooks;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.extractHooks = extractHooks;
|
|
@ -369,11 +369,13 @@
|
||||||
document.domain = document.domain; // for comet
|
document.domain = document.domain; // for comet
|
||||||
}
|
}
|
||||||
|
|
||||||
var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
|
var plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
|
||||||
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
|
|
||||||
plugins.baseURL = baseURL;
|
plugins.baseURL = baseURL;
|
||||||
plugins.update(function () {
|
plugins.update(function () {
|
||||||
|
hooks.plugins = plugins;
|
||||||
|
|
||||||
// Call documentReady hook
|
// Call documentReady hook
|
||||||
$(function() {
|
$(function() {
|
||||||
hooks.aCallAll('documentReady');
|
hooks.aCallAll('documentReady');
|
||||||
|
|
|
@ -175,10 +175,13 @@
|
||||||
document.domain = document.domain; // for comet
|
document.domain = document.domain; // for comet
|
||||||
}
|
}
|
||||||
|
|
||||||
var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
|
var plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
|
||||||
plugins.baseURL = baseURL;
|
plugins.baseURL = baseURL;
|
||||||
|
|
||||||
plugins.update(function () {
|
plugins.update(function () {
|
||||||
|
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
|
hooks.plugins = plugins;
|
||||||
|
|
||||||
var timeslider = require('ep_etherpad-lite/static/js/timeslider')
|
var timeslider = require('ep_etherpad-lite/static/js/timeslider')
|
||||||
timeslider.baseURL = baseURL;
|
timeslider.baseURL = baseURL;
|
||||||
timeslider.init();
|
timeslider.init();
|
||||||
|
|
Loading…
Reference in New Issue