nitro-template

powerful javascript template engine

MIT 19 个版本
安装
npm install nitro-template
yarn add nitro-template
pnpm add nitro-template
bun add nitro-template
README

nitro-template wercker status

npm version Build Status

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 2016-11-15
0.2.12 2016-09-08
0.2.11 2016-08-24
0.2.10 2016-08-24
0.2.9 2016-04-21
0.2.8 2016-04-21
0.2.7 2016-04-12
0.2.6 2016-04-06
0.2.5 2016-04-06
0.2.4 2016-04-06
0.2.3 2016-04-05
0.2.2 2016-04-05
0.2.1 2016-04-05
0.2.0 2016-04-05
0.1.6 2015-10-09
0.1.5 2015-10-08
0.1.4 2015-10-05
0.1.3 2015-09-29
0.1.2 2015-09-29