A simple CLI tool for templating using Handlebars.
For information on syntax and other Handlebars specifics check out this guide.
It might be installed as a global tool to render a simple mustache/handlebars template of some kind
$ npm install -g flatbars
$ flatbars dataView.json myTemplate.handlebars > output.htmlor as a package.json devDependency in a build process
$ npm install flatbars --save-dev{
"scripts": {
"build": "flatbars dataView.json myTemplate.handlebars > dist/output.html"
}
}$ npm run buildIn order to use Handlebar helpers you just need to create a js file that exposes a register function. This function is going to be called with the Handlebars instance as first argument.
// helpers.js
const helpers = () => { }
helpers.register = function (Handlebars) {
Handlebars.registerHelper('loud', (s) => s.toUpperCase());
}
module.exports = helpers;{
"title": "This is my title!"
}To render just run this:
$ flatbars dataView.json myTemplate.handlebars helpers.js > output.htmlUsing partials on your template is also simple, you just pass paths to partials using -p flag:
{
"people": [
{
"firstname": "John",
"lastname": "Doe"
},
{
"firstname": "Janne",
"lastname": "Smith"
},
{
"firstname": "Richard",
"lastname": "Miles"
}
]
}$ flatbars -p partial.handlebars dataView.json myTemplate.handlebars > output.htmlIt also supports stdin, just pass '-' as your data view argument:
$ cat dataView.json | flatbars -p partial.handlebars - myTemplate.handlebars helpers.js > output.html