trisquel

JS template engine

MIT 26 个版本
安装
npm install trisquel
yarn add trisquel
pnpm add trisquel
bun add trisquel
README

trisquel

Simple, customizable template engine for JavaScript

Build Status GitHub license

Installation

npm install trisquel --save

Example data

var data = {
  foo: 'bar',
  crash: {
    test: 'dummy'
  },
  list: ['foo', 'bar', 'foobar'],
  map: {
    hi: 'all',
    bye: 'nobody'
  }
};

Caching templates

template.put('partial-map', '$each{ item,key in map }[${foo}:${key}:${item}]{/}');

template.put('partial-list', '$each{ item,i in list }[${foo}:${i}:${item}]{/}');

// cached templates can be invoked with $include{}

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]'

Filters


template.filter('months', function (nMonths) {
  return nMonths + (nMonths > 1 ? ' meses' : ' mes' );
});

console.log( template('${ nMonths | months }')({ nMonths: 5 }) );
// returns '5 meses'
console.log( template('${ nMonths | months }')({ nMonths: 1 }) );
// returns '1 mes'

var messages {
  greeting: template('Hi ${name}!')
};

template.filter('message', function (key, data) {
  return messages[key](data);
});

console.log( template('${ person.last_name }: ${ \'greeting\' | message: { name: person.first_name } }')({
  person: {
    first_name: 'John',
    last_name: 'Smith'
  }
}) );
// returns 'Smith: Hi John!'

Tests

npm test

Build Status Travis

wercker status Wercker

版本列表
1.1.5 2018-02-07
1.1.4 2018-02-06
1.1.3 2018-02-06
1.1.2 2018-02-06
1.1.1 2018-02-05
1.0.27 2017-04-28
1.0.26 2017-04-28
1.0.25 2017-04-28
1.0.24 2017-04-28
1.0.22 2017-04-28
1.0.16 2017-04-28
1.0.14 2017-04-28
1.0.13 2017-04-28
1.0.11 2017-04-28
1.0.10 2017-04-28
1.0.9 2017-04-28
1.0.8 2017-04-28
1.0.7 2017-04-28
1.0.6 2017-01-25
1.0.4 2017-01-25
1.0.3 2016-12-20
1.0.2 2016-12-20
1.0.1 2016-12-20
1.0.0 2016-12-19
0.4.0 2016-12-19
0.0.1 2016-12-10