dombarsify

DOMBars precompiler plugin for Browserify

npm install dombarsify
3 downloads in the last week
17 downloads in the last month

dombarsify

DOMBars pre-compilation plugin for Browserify. Compiles DOMBars/Handlebars templates into plain JavaScript. All compiled templates include only the DOMBars runtime and the precompiled template, so they are several factors faster and lightweight than including and parsing the original template.

Usage

Install dombarsify locally to your project.

npm install dombarsify

DOMBars will be installed automatically as a peer dependency, which allows for finer grain control over versioning. You can now use it as a transform with your module.

browserify -t dombarsify main.js -o bundle.js

To require a template within main.js, you can simply require the file itself.

var template = require('./template.hbs');
document.body.appendChild(template({ user: 'blakeembrey' }));

The template file, be default, can use .hbs, .handlebars, .dom or .dombars extensions. The template itself is just regular text.

<p>Welcome back, {{user}}</p>

Programmatic Usage

Custom extensions

Using another unhandled extension? Just add it to the extensions object on the main function.

var dombarsify = require('dombarsify');

dombarsify.extensions.html = true;

Helpers

To register a custom helper function, just require the DOMBars runtime and use registerHelper as your normally would.

var dombars = require('dombars/runtime');

dombars.registerHelper('upper', function (string) {
  return string.toUpperCase();
});

Partials

Partials can be included by passing a precompiled template to the registerPartial function.

var dombars = require('dombars/runtime');

dombars.registerPartial('button', require('./button.hbs'));

License

MIT

npm loves you