simplator-subtemplates

Simplator filters to run sub-templates

simplator-subtemplates

Simplator filters to run sub-templates. Allow simplator to run sub-templates

Install the module with: npm install simplator-subtemplates --save

 
var fs =require("fs"),
    simplator = require("simplator"),
 
    templates = {
        nameTmpl:  simplator.compile("{first},{last}"),
        addressTmpl:  simplator.compile("{street},{city}")
    },
 
    subTemplates = require('simplator-subtemplates');
 
subTemplates.use(templates);
 
var tmplt = simplator.compile("{name | sub('nameTmpl')}\n{address | sub('addressTmpl') }"),
 
    results = tmplt({
        name:{
            first: "Andrea",
            last: "Parodi"
        },
        address: {
            street: "via Casata",
            city: "Genoa"
        }
    });

Results will contains "Andrea,Parodi\nvia Casata,Genoa"

OR, to render arrays sub-context, use:

var tmplt = simplator.compile("{name | sub('nameTmpl')}\n{addresses | subEach('addressTmpl','\t') }");
 
results = tmplt({
   name: {
       first: "Andrea",
       last: "Parodi"
   },
   addresses: [{
       street: "via Casata",
       city: "Genoa"
   },{
       street: "Another address",
       city: "Roma"
   }]
});

Results will contains "Andrea,Parodi\nvia Casata,Genoa\tAnother address,Roma"

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

Copyright (c) 2013 parroit
Licensed under the MIT license.