meta-templater
Flexible templates parser inspired by gulp-file-include.
Installation
$ npm i meta-templater
Theory
Template has three types of constructions:
var
//= var_name
Where //=
is prefix and suffix is empty
fn
//= include[]
Where include
is fn
name and []
is argument js object (array)
op
//= print ( content )
//= each[] ()
Where arguments is optinal and ()
is body of op
Initialize
compile.js
var MT = fs = ; var result = ; fs;
Examples
Condition Handler
index.html
//= if[data.voice] ( Hello, //= name)
Include Handler
index.html
//= include['head.html', {title: 'Page Title'}] //= include['header.html'] //= include['content-main.html'] //= include['footer.html']
head.html
<!-- Empty string for indent correction --> //= title
API
new MT(options);
Initialize templater
options.prefix
Type: String
Default: //=
options.suffix
Type: String
Default: ``
options.open
Type: String
Default: (
options.close
Type: String
Default: )
Methods
addFn(name, handler);
addOp(name, handler);
this
methods
Handler build(input || body, data)
flatten(input || body)
License
Copyright © 2015 Bogdan Chadkin