mostly handlebars compatible template engine with logic
npm install tbt``javascript`
/ __ ___. __
_/ |\_ |___/ |_
\ __\ __ \ __\
| | | \_\ \ |
|__| |___ /__|
(c)toyboy \/ 2016 /
Tiny and mostly ~~harmless~~ handlebars compatible template engine
#### Tiny!
The whole thing (compiler and all) comes in at 19kb (under 8kb minified), the "runtime" part (included in compiled template/partial/helper bundle) weights around 860 bytes minified and around 430 bytes if no looping support is needed!
As a comparison: handlebars (with compiler and all) is 75kb minified and even the runtime is 16kb when minified, you know you could fit the full tbt twice in that space, just saying.. still a bit fat compared to doT.js though..
#### How to use?
`bash`
npm intall tbt -g`javascript
var tbt = require('tbt');
// sets the default search path for templates, we assume templates have the extension .tbt
tbt.path = '/var/www/templates/';
// tbt will look for /var/www/templates/myTemplate.tbt compile it and run it with data given
tbt('myTemplate', {here: {is: ['my','data'] } }, function(err, text) {
if(!err) {
console.log(text);
}
});
var fs = require('fs');
// Export returns the "runtime" version of all templates/partials/helpers in cache (loaded in with the same tbt in the same session)
fs.writeFileSync('myCompiledTemplates.js', tbt.export());
```html``
...
...
Few more examples can be found in examples/ folder and in the few tests included.
#### Logic
Supports:
* if / else if / else
* each
* < (save partial)
* \> (load partial)
* = variable ? true : false (ternary, adds result to output)
* variable = 1 + 1 (assigning variables inline)
#### Why?
Handlebars is too big (and lacks alot of logic) and doT is a bit too simple (+ it doesn't even try to be handlebars compatible'ish). And a lot of these template engines that advertise "light weight" "small compiled templates" etc. actually are quite big when you add the runtime needed to actually get any output from the template.
And because why not? How hard can it be? :)
#### License
tbt is licensed under the MIT license (see LICENSE)
##### Inspired by:
doT.js by Laura Doktorova
Handlebars.js by Yehuda Katz
And by this article by Krasimir Tsonev