README
templum
___ ___ ___ ___ ___
___ / /\ /__/\ / /\ /__/\ /__/\
/ /\ / /:/_ | |::\ / /::\ \ \:\ | |::\
/ /:/ / /:/ /\ | |:|:\ / /:/\:\ ___ ___ \ \:\ | |:|:\
/ /:/ / /:/ /:/_ __|__|:|\:\ / /:/~/:/ /__/\ / /\ ___ \ \:\ __|__|:|\:\
/ /::\ /__/:/ /:/ /\ /__/::::| \:\ /__/:/ /:/ \ \:\ / /:/ /__/\ \__\:\ /__/::::| \:\
/__/:/\:\ \ \:\/:/ /:/ \ \:\~~\__\/ \ \:\/:/ \ \:\ /:/ \ \:\ / /:/ \ \:\~~\__\/
\__\/ \:\ \ \::/ /:/ \ \:\ \ \::/ \ \:\/:/ \ \:\ /:/ \ \:\
\ \:\ \ \:\/:/ \ \:\ \ \:\ \ \::/ \ \:\/:/ \ \:\
\__\/ \ \::/ \ \:\ \ \:\ \__\/ \ \::/ \ \:\
\__\/ \__\/ \__\/ \__\/ \__\/
Install
$ npm install @slietar/templum --save
Getting started
var templum = require('@slietar/templum');
templum.mustache.static('lorem {{foo}}', { locals: { foo: 'ipsum' } })
.then((data) => {
console.log(data.toString());
});
// Outputs `lorem ipsum`
Using streams:
var templum = require('@slietar/templum');
getReadableStream().pipe(templum.mustache({ locals: { ... } })).pipe(getWritableStream());
// for example:
process.stdin.pipe(templum.mustache()).pipe(process.stdout);
Supported template engines
See engines.md
for more info.
- dot (planned)
- ejs (planned)
- haml (planned)
- handlebars
- html
- jade
- mustache
- nunjucks
- text
- swig
- underscore
Options
{
cache: false, /* boolean */
debug: false, /* boolean */
filename: null, /* string */
locals: {}, /* object */
style: Style.Default, /* enum: default, compact, compressed, expanded */
[custom options]
}
Usage with TypeScript
$ npm install @slietar/templum --save
$ tsd link
$ tsd install node --save
$ tsc
Writing a template engine
var templum = require('@slietar/templum');
module.exports = templum.engine((input, output) => {
// input and output are both `through2` streams
input.on('data', (chunk) => {
output.write(...);
});
input.on('end', () => {
// don't forget this
output.end();
});
// OR
input.pipe(...).pipe(output);
// OR
// input.concat() and output.throw() are two special methods
input.concat()
.then((data) => {
output.end(...);
})
.catch(output.throw);
});
Development
$ npm test
$ npm run coverage
Change log
0.2.0
- add
handlebars
,nunjucks
,swig
andunderscore
template engines findFromExtension
allows a.
at the beginning- move
jade
andmustache
to peer dependencies - move
lib/a.js
toa.js
and addtemplum.a
- remove
Q
- remove
templum.default
- use streams (
concat-stream
,duplexer2
,through2
)
0.1.1
- fix TS definition bug
0.1.0
- initial version