Merge branch 'develop' into fix/max-age
This commit is contained in:
commit
137e06d52b
|
@ -6,6 +6,7 @@ var settings = require("../../utils/Settings");
|
|||
var Yajsml = require('yajsml');
|
||||
var fs = require("fs");
|
||||
var ERR = require("async-stacktrace");
|
||||
var _ = require("underscore");
|
||||
|
||||
exports.expressCreateServer = function (hook_name, args, cb) {
|
||||
// Cache both minified and static.
|
||||
|
@ -35,8 +36,22 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
|||
// serve plugin definitions
|
||||
// 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) {
|
||||
|
||||
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.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts}));
|
||||
res.write(JSON.stringify({"plugins": clientPlugins, "parts": clientParts}));
|
||||
res.end();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -50,10 +50,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;
|
||||
|
@ -62,10 +64,14 @@ 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 {
|
||||
|
|
Loading…
Reference in New Issue