0.3.0 • Published 11 years ago

handlebarizer v0.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
11 years ago

handlebarizer

Solution for compiling handlebars templates into vanilla JS functions for client-side use. Inspired by HenrikJoreteg/templatizer

example

template.hbs:

<div>{{name}}</div>

template.hbs.js:

module.exports = function (Handlebars, depth0, helpers, partials, data) {
  helpers = helpers || Handlebars.helpers;
  var buffer = "",
    stack1, foundHelper, functionType = "function",
    escapeExpression = this.escapeExpression;


  buffer += "<div>";
  foundHelper = helpers.name;
  if (foundHelper) {
    stack1 = foundHelper.call(depth0, {
      hash: {}
    });
  } else {
    stack1 = depth0.name;
    stack1 = typeof stack1 === functionType ? stack1() : stack1;
  }
  buffer += escapeExpression(stack1) + "</div>";
  return buffer;
};

Then the template can be used:

var handlebars = require('handlebars')

var template = handlebars.template(require('./template.hbs.js'))
var html = template({
  name: 'Sérgio Ramos'
})

install

npm install [-g] handlebarizer

api

var handlebarizer = require('handlebarizer')

handlebarizer('./templates', function (e) {
  if(e) throw e
  console.log('all templates compiled and saved to disk')
})

cli

Usage: handlebarizer [options] [command]

Commands:

  compile <path>

Options:

  -h, --help       output usage information
  -V, --version    output the version number
  -r, --recursive  recursively compile throughout the directory tree

license

MIT

0.3.0

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago