0.2.13 • Published 7 years ago
nitro-template v0.2.13
nitro-template
Installation
npm install nitro-template --save
Usage
var data = {
foo: 'bar',
crash: {
test: 'dummy'
},
list: ['foo', 'bar', 'foobar'],
map: {
hi: 'all',
bye: 'nobody'
}
};
template.put('partial-map', '$each{ item,key in map }[${foo}:${key}:${item}]{/}');
template.put('partial-list', '$each{ item,i in list }[${foo}:${i}:${item}]{/}');
console.log( template('$if{ foo !== \'bar\' }whoops{:}map: $include{\'partial-map\'} {/}', data) );
// returns 'map: [bar:hi:all][bar:bye:nobody]'
console.log( template('$if{ foo !== \'bar\' }whoops{:}list: $include{\'partial-list\'} {/}', data) );
// returns 'list: [bar:0:foo][bar:1:bar][bar:2:foobar]'
var i18n = {
months: '${n} mes$if{ n > 1 }es{/}'
};
template.filter('i18n', function (key, data) {
if( data ) {
return template(i18n[key.trim()])(data);
}
return i18n[key.trim()];
});
console.log( template('${ \'months\' | i18n:{ n: 5 } }')() );
// returns '5 meses'
console.log( template('${ \'months\' | i18n:{ n: 1 } }')() );
// returns '1 mes'
0.2.13
7 years ago
0.2.12
8 years ago
0.2.11
8 years ago
0.2.10
8 years ago
0.2.9
8 years ago
0.2.8
8 years ago
0.2.7
8 years ago
0.2.6
8 years ago
0.2.5
8 years ago
0.2.4
8 years ago
0.2.3
8 years ago
0.2.2
8 years ago
0.2.1
8 years ago
0.2.0
8 years ago
0.1.6
9 years ago
0.1.5
9 years ago
0.1.4
9 years ago
0.1.3
9 years ago
0.1.2
9 years ago