Hand written, not tested, using expression expansion of ${ } using simpletpl
https://github.com/ajlopez/SimpleTpl/blob/master/test/templateWithModel.js
You can put js expressions not only variables, in ${ }

var simpletpl = require('simpletpl');

```js
var object = {
   name: 'bu++',
   cflags: '-stdlib=libc++',
   deps: [ 'lib${name}' ],
   rule: [
      {
         name: 'cxx',
         command: 'gcc ${cflags} -c <in> -o <out>',
      }
   ]
}

for (var n in object) {
    var data = object[n];

    if (typeof data == 'string' && data.indexOf('${') >= 0)
        object[n] = doTemplate(data,object);
}

function doTemplate(text, model)
{
    var template = simpletpl.compileTemplate(text);
    return template(model);
}


On Tue, Feb 4, 2014 at 7:02 AM, Alex Kocharin <[email protected]> wrote:

>
> 04.02.2014, 13:55, "Gagle" <[email protected]>:
>
> Variable expansion is not that easy, Alex.
>
> You can have variables inside other variables, something like:
>
> ${foo${bar}baz}
>
>
> That's why you do it in the loop. It is easy, really. My code would work
> with it if you only change regexp to /\$\{[\w+]\}/ (add {} in there).
>
> Circular references can be a bit harder, I guess it'd take an hour instead
> of 10 minutes. :P
>
> It is usually hard to came up with a certain idea how it should work, and
> what syntax should it have. But if you have pretty good picture of what you
> can do, it's all easy. I implemented a complete JSON5 parser in just 10
> hours some time ago, with all original tests passing. ;)
>
>
>
>
> For Kevin and any one interested:
>
> https://github.com/gagle/node-properties/blob/master/lib/read.js#L19
>
> This function expands things like:
>
> ${section|property}
>
> El lunes, 3 de febrero de 2014 13:10:42 UTC+1, Ali Davut escribió:
>
> Hi, we just published a new library, we expect this will help you to make
> configuration files easier https://github.com/vngrs/konfig
>
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>  --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to