/yeoman-handlebars-engine

Write yeoman generator templates in handlebars

Primary LanguageCoffeeScript

yeoman-handlebars-engine NPM version Build Status

Write Yeoman generator templates in Handlebars with Underscore.string helpers.

> npm install yeoman-handlebars-engine

Use it in your generator:

handlebarsEngine = require 'yeoman-handlebars-engine'

class RobotGenerator extends yeoman.generators.Base
  engine: handlebarsEngine()
  constructor: (args, options, config) ->
    super

Setting custom helpers:

handlebarsEngine = require 'yeoman-handlebars-engine'
theEngine = handlebarsEngine {fns: {toLowerCase: (str) -> str.toLowerCase()}}

Setting directory where Handlebar partials reside:

handlebarsEngine = require 'yeoman-handlebars-engine'
theEngine = handlebarsEngine {partials: 'partials/'}

Using Underscore.string helpers in your generator templates:

@myClass = 'robot generator'
@bigNumber = 123456789.123
My class: {{ classify myClass}}
Big number: {{ numberFormat bigNumber 5 "." ","}}

Outputs:

My class: RobotGenerator
Big number: 123,456,789.12300

Changelog

v1.0

Breaking change: Export a function that configures Handlebars and returns an engine, instead of exporting the engine directly.