add 'macroize' to utils

This commit is contained in:
Scott Miles
2012-10-26 14:57:44 -07:00
parent 0c2dd16dc0
commit 3a36f630c1

View File

@@ -440,12 +440,24 @@ license that can be found in the LICENSE file.
} }
}; };
// string interpolation
var macroize = function(inText, inMap, inPattern) {
var result = inText, pattern = inPattern || macroize.pattern;
var fn = function(macro, name) {
var v = inMap[name];
return (v === undefined || v === null) ? macro : v;
}; };
result = result.replace(pattern, fn);
return result;
};
// Matches macros of the form {{name}}.
macroize.pattern = /\{{([^{}]*)\}}/g;
// collect utils // collect utils
var utils = { var utils = {
job: job, job: job,
macroize: macroize,
findDistributedTarget: findDistributedTarget findDistributedTarget: findDistributedTarget
}; };