Skip to content

Commit

Permalink
fix(config.get): process intermediate templates in path
Browse files Browse the repository at this point in the history
  • Loading branch information
linoleum-js committed Jun 19, 2016
1 parent 662bd69 commit 4eb5100
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/grunt/config.js
Expand Up @@ -43,7 +43,28 @@ var propStringTmplRe = /^<%=\s*([a-z0-9_$]+(?:\.[a-z0-9_$]+)*)\s*%>$/i;

// Get config data, recursively processing templates.
config.get = function(prop) {
return config.process(config.getRaw(prop));
var props = getParts(config.getPropString(prop));
var currentData = config.data;
// from https://github.com/cowboy/node-getobject/blob/master/lib/getobject.js
// Split strings on dot, but only if dot isn't preceded by a backslash. Since
// JavaScript doesn't support lookbehinds, use a placeholder for "\.", split
// on dot, then replace the placeholder character with a dot.
function getParts(str) {
return str.replace(/\\\./g, '\uffff').split('.').map(function(s) {
return s.replace(/\uffff/g, '.');
});
}

props.forEach(function(item) {
currentData = currentData[item];
// if current value is template -- expand it
if (typeof currentData === 'string' &&
currentData.match(propStringTmplRe)) {
currentData = config.process(currentData);
}
});

return config.process(currentData);
};

// Expand a config value recursively. Used for post-processing raw values
Expand Down

0 comments on commit 4eb5100

Please sign in to comment.