Skip to content

Commit f9071ef

Browse files
committed
Adding config.process method to process raw values already retrieved from config data.
1 parent 14b824e commit f9071ef

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/grunt/config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ var propStringTmplRe = /^<%=\s*([a-z0-9_$]+(?:\.[a-z0-9_$]+)*)\s*%>$/i;
5252

5353
// Get config data, recursively processing templates.
5454
config.get = function(prop) {
55-
return grunt.util.recurse(config.getRaw(prop), function(value) {
55+
return config.process(config.getRaw(prop));
56+
};
57+
58+
// Expand a config value recursively. Used for post-processing raw values
59+
// already retrieved from the config.
60+
config.process = function(raw) {
61+
return grunt.util.recurse(raw, function(value) {
5662
// If the value is not a string, return it.
5763
if (typeof value !== 'string') { return value; }
5864
// If possible, access the specified property via config.get, in case it

test/grunt/config_test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ exports['config'] = {
4747
test.deepEqual(grunt.config.getRaw('arr'), ['foo', '<%= obj.foo2 %>'], 'Should not process templates.');
4848
test.done();
4949
},
50+
'config.process': function(test) {
51+
test.expect(5);
52+
test.equal(grunt.config.process('<%= meta.foo %>'), 'bar', 'Should process templates.');
53+
test.equal(grunt.config.process('<%= foo %>'), 'bar', 'Should process templates recursively.');
54+
test.equal(grunt.config.process('<%= obj.foo %>'), 'bar', 'Should process deeply nested templates recursively.');
55+
test.deepEqual(grunt.config.process(['foo', '<%= obj.foo2 %>']), ['foo', 'bar'], 'Should process templates in arrays.');
56+
test.deepEqual(grunt.config.process(['<%= arr %>', '<%= obj.Arr %>']), [['foo', 'bar'], ['foo', 'bar']], 'Should expand <%= arr %> and <%= obj.Arr %> values as objects if possible.');
57+
test.done();
58+
},
5059
'config.get': function(test) {
5160
test.expect(8);
5261
test.equal(grunt.config.get('foo'), 'bar', 'Should process templates.');

0 commit comments

Comments
 (0)