Home

Awesome

sbt-hbs Build Status

sbt-web plugin for precompiling handlebars templates to javascript files, using the handlebarsjs compiler.

Installation

To use this plugin use the addSbtPlugin command within your project's plugins.sbt file:

resolvers += Resolver.sbtPluginRepo("releases")

addSbtPlugin("com.bicou.sbt" % "sbt-hbs" % "1.0.5")

Your project's build file also needs to enable sbt-web plugins. For example with build.sbt:

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

Install handlebarsjs, either globally with npm:

npm install handlebars -g

Or locally in your project with a package.json file:

{
  "devDependencies": {
    "handlebars": "^3.0.0"
  }
}

Supported settings

OptionDescriptionDefault
amdWhen set, generates JavaScript with the AMD wrapperfalse
commonjsExports CommonJS style, path to Handlebars module""
handlebarPathPath to handlebar.js (only valid for amd-style)""
knownKnown helpers[]
knownOnlyKnown helpers onlyfalse
namespaceTemplate namespace""
rootTemplate root (base value that will be stripped from template names)""
dataInclude data when compilingfalse
bomRemoves the BOM (Byte Order Mark) from the beginning of the templatesfalse
simpleOutput template function onlyfalse
mapGenerates source mapsfalse

The following sbt code illustrates how to generate templates with AMD wrapper

HbsKeys.amd := true

Usage

Once configured, any *.hbs or *.handlebars files placed in src/main/assets will be compiled to JavaScript code in target/web/public, the handlebars name is build from file path, relative to root option.

For example the name of the template located in app/assets/javascripts/templates/index.hbs will be javascripts/templates/index, unless you set HbsKeys.root := "javascripts/templates/" then it will be index (it's the handlebars id, not the javascript path).

If a file name begins with an underscore, it will be handled as a partial.

Don't forget to include the handlebars runtime via "org.webjars" % "handlebars" % "3.0.0-1" or by copying/linking in your public javascripts (node_modules/handlebars/dist/handlebars.runtime.js with npm).

Example

Browse play-rjs-coffee-hbs repository to see usage with play framework.

License

This code is licensed under the MIT License.