Permalink
Browse files

Merge pull request #1243 from lgenet/ts-register-for-each

Template Service - Register Locals for Each
  • Loading branch information...
brianhyder committed Apr 11, 2017
2 parents c5ff27a + b0622ad commit 522def1148a159d5f46d8361a5558149ced6c924
Showing with 36 additions and 0 deletions.
  1. +36 −0 include/service/entities/template_service.js
@@ -631,6 +631,42 @@ module.exports = function(pb) {
return true;
};
/**
* Takes in the below parameters and returns a single TemplateValue that is the combination of
* all items in list, after being ran through the renderFunction.
*
* @param list - The list of data to be used
* @param renderFunction - A function that each item in the list will be ran against
* @param cb - yields error if one occurred, or a single TemplateValue that is the join of
* all values that were returned by the render function
* @returns {*}
*/
TemplateService.prototype.registerLocalForEach = function (list, renderFunction, processFunc, cb) {
// Handle Optional processFunction
if(!cb){
cb = processFunc;
processFunc = function(e) {return e;};
}
if (!list) {
return cb(null, '');
}
else if (!util.isArray(list)) {
list = [list];
}
var tasks = pb.util.getTasks(list, function (item, i) {
return function (callback) {
renderFunction(item[i], callback);
};
});
async.parallel(tasks, function (err, results) {
results = processFunc(results);
cb(err, new pb.TemplateValue(results.join(''), false));
});
};
/**
* Registers a model with the template service. It processes each
* key/value pair in the object and creates a dot notated string

0 comments on commit 522def1

Please sign in to comment.