diff --git a/reconfig.js b/reconfig.js index 20c21e7..98583dc 100644 --- a/reconfig.js +++ b/reconfig.js @@ -95,7 +95,9 @@ Reconfig.prototype.resolveReferences = function(value) { */ Reconfig.prototype.resolveParameters = function(value, parameters) { for (var property in parameters) { - value = (value) ? value.replace(':' + property, (parameters[property] || '')) : value; + if (value) { + value = value.replace(RegExp(':' + property, 'g'), (parameters[property] || '')); + } } return value; diff --git a/test.js b/test.js new file mode 100644 index 0000000..ee39a85 --- /dev/null +++ b/test.js @@ -0,0 +1,18 @@ +var rec = require('./reconfig.js'); +var c = { + root: { + a: 'valA', + b: { + c: '{{ root.a }}', + d: 'valD:paramD' + }, + e: 'valE:paramE', + f: 'valeF {{root.b.d}}' + } +}; + +var conf = new rec(c); + +console.log('conf: ', conf); +console.log('conf paramD: ', conf.get('root', {paramD: 'ddddddddddd'})); +console.log('conf app params: ', conf.get('root', {paramD: 'ddddddddddd', paramE: 'eeeeeeeeeeeeeeee'})); diff --git a/test/reconfig.js b/test/reconfig.js index 916202e..7252e3e 100644 --- a/test/reconfig.js +++ b/test/reconfig.js @@ -125,6 +125,20 @@ describe('Reconfig', function() { })); }); + it('should be able to render parmas in composite values', function() { + var values = { + a: { + b: 'hello :what!' + }, + c: '{{ a.b }}, :what' + }; + var config = new reconfig(values); + + assert('hello world!, world' === config.get('c', { + what: 'world' + })); + }); + it('should be able to handle self-referencing configs', function() { var values = { a: {