1.1.5 • Published 6 years ago

trisquel v1.1.5

Weekly downloads
36
License
MIT
Repository
github
Last release
6 years ago

trisquel

Simple, customizable template engine for JavaScript

npm.io 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

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.0.28

6 years ago

1.1.1

6 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.22

7 years ago

1.0.16

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.4.0

7 years ago

0.0.1

7 years ago