summaryrefslogtreecommitdiff
path: root/src/static/js/pluginfw
diff options
context:
space:
mode:
authorMatthias Bartelmeß <mba@fourplusone.de>2012-03-17 13:36:42 +0100
committerMatthias Bartelmeß <mba@fourplusone.de>2012-03-17 13:38:26 +0100
commite559df18ce7876c497bd6da64c3a1c0346f211f4 (patch)
tree71262d36dadb8ae745a4c985ec8610bf5b4c67da /src/static/js/pluginfw
parent692e77b4e5a0322bc19cb49cc60a63146073e359 (diff)
downloadetherpad-lite-e559df18ce7876c497bd6da64c3a1c0346f211f4.zip
use underscore.js
Diffstat (limited to 'src/static/js/pluginfw')
-rw-r--r--src/static/js/pluginfw/hooks.js7
-rw-r--r--src/static/js/pluginfw/plugins.js34
2 files changed, 25 insertions, 16 deletions
diff --git a/src/static/js/pluginfw/hooks.js b/src/static/js/pluginfw/hooks.js
index 1b09a6e5..dbf8e583 100644
--- a/src/static/js/pluginfw/hooks.js
+++ b/src/static/js/pluginfw/hooks.js
@@ -1,10 +1,13 @@
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
+var _;
/* FIXME: Ugly hack, in the future, use same code for server & client */
if (plugins.isClient) {
- var async = require("ep_etherpad-lite/static/js/pluginfw/async");
+ var async = require("ep_etherpad-lite/static/js/pluginfw/async");
+ _ = require("underscore");
} else {
var async = require("async");
+ _ = require("underscore");
}
var hookCallWrapper = function (hook, hook_name, args, cb) {
@@ -34,7 +37,7 @@ exports.flatten = function (lst) {
exports.callAll = function (hook_name, args) {
if (plugins.hooks[hook_name] === undefined) return [];
- return exports.flatten(plugins.hooks[hook_name].map(function (hook) {
+ return exports.flatten(_.map(plugins.hooks[hook_name], function (hook) {
return hookCallWrapper(hook, hook_name, args);
}));
}
diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js
index 9e85f6fc..0745b698 100644
--- a/src/static/js/pluginfw/plugins.js
+++ b/src/static/js/pluginfw/plugins.js
@@ -1,5 +1,7 @@
exports.isClient = typeof global != "object";
+var _;
+
if (!exports.isClient) {
var npm = require("npm/lib/npm.js");
var readInstalled = require("npm/lib/utils/read-installed.js");
@@ -10,10 +12,12 @@ if (!exports.isClient) {
var fs = require("fs");
var tsort = require("./tsort");
var util = require("util");
+ _ = require("underscore");
}else{
- require("../ace2_common.js");
- var $, jQuery;
+ var $, jQuery
$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
+ _ = require("ep_etherpad-lite/static/js/underscore");
+
}
exports.prefix = 'ep_';
@@ -30,17 +34,17 @@ exports.ensure = function (cb) {
}
exports.formatPlugins = function () {
- return Object.keys(exports.plugins).join(", ");
+ return _.keys(exports.plugins).join(", ");
}
exports.formatParts = function () {
- return exports.parts.map(function (part) { return part.full_name; }).join("\n");
+ return _.map(exports.parts, function (part) { return part.full_name; }).join("\n");
}
exports.formatHooks = function () {
var res = [];
- Object.keys(exports.hooks).forEach(function (hook_name) {
- exports.hooks[hook_name].forEach(function (hook) {
+ _.chain(exports.hooks).keys().forEach(function (hook_name) {
+ _.forEach(exports.hooks[hook_name], function (hook) {
res.push(hook.hook_name + ": " + hook.hook_fn_name + " from " + hook.part.full_name);
});
});
@@ -50,7 +54,7 @@ exports.formatHooks = function () {
exports.loadFn = function (path) {
var x = path.split(":");
var fn = require(x[0]);
- x[1].split(".").forEach(function (name) {
+ _.each(x[1].split("."), function (name) {
fn = fn[name];
});
return fn;
@@ -58,8 +62,8 @@ exports.loadFn = function (path) {
exports.extractHooks = function (parts, hook_set_name) {
var hooks = {};
- parts.forEach(function (part) {
- Object.keys(part[hook_set_name] || {}).forEach(function (hook_name) {
+ _.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];
var hook_fn = exports.loadFn(part[hook_set_name][hook_name]);
@@ -114,7 +118,7 @@ exports.getPackages = function (cb) {
if (er) cb(er, null);
var packages = {};
function flatten(deps) {
- Object.keys(deps).forEach(function (name) {
+ _.chain(deps).keys().each(function (name) {
if (name.indexOf(exports.prefix) == 0) {
packages[name] = deps[name];
}
@@ -141,7 +145,7 @@ exports.loadPlugin = function (packages, plugin_name, plugins, parts, cb) {
var plugin = JSON.parse(data);
plugin.package = packages[plugin_name];
plugins[plugin_name] = plugin;
- plugin.parts.forEach(function (part) {
+ _.each(plugin.parts, function (part) {
part.plugin = plugin_name;
part.full_name = plugin_name + "/" + part.name;
parts[part.full_name] = part;
@@ -156,11 +160,11 @@ exports.loadPlugin = function (packages, plugin_name, plugins, parts, cb) {
exports.partsToParentChildList = function (parts) {
var res = [];
- Object.keys(parts).forEach(function (name) {
- (parts[name].post || []).forEach(function (child_name) {
+ _.chain(parts).keys().forEach(function (name) {
+ _.each(parts[name].post || [], function (child_name) {
res.push([name, child_name]);
});
- (parts[name].pre || []).forEach(function (parent_name) {
+ _.each(parts[name].pre || [], function (parent_name) {
res.push([parent_name, name]);
});
if (!parts[name].pre && !parts[name].post) {
@@ -170,6 +174,8 @@ exports.partsToParentChildList = function (parts) {
return res;
}
+
+// Used only in Node, so no need for _
exports.sortParts = function(parts) {
return tsort(
exports.partsToParentChildList(parts)