Merge branch 'develop' into fix/max-age

This commit is contained in:
Matthias Bartelmeß 2012-04-04 17:42:08 +02:00
commit 137e06d52b
2 changed files with 26 additions and 5 deletions

View File

@ -6,6 +6,7 @@ var settings = require("../../utils/Settings");
var Yajsml = require('yajsml'); var Yajsml = require('yajsml');
var fs = require("fs"); var fs = require("fs");
var ERR = require("async-stacktrace"); var ERR = require("async-stacktrace");
var _ = require("underscore");
exports.expressCreateServer = function (hook_name, args, cb) { exports.expressCreateServer = function (hook_name, args, cb) {
// Cache both minified and static. // Cache both minified and static.
@ -35,8 +36,22 @@ exports.expressCreateServer = function (hook_name, args, cb) {
// serve plugin definitions // serve plugin definitions
// not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js"); // 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) { 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.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(); res.end();
}); });
} }

View File

@ -50,10 +50,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;
@ -62,10 +64,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 {