Code Monkey home page Code Monkey logo

sbt-hbs's Introduction

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

Option Description Default
amd When set, generates JavaScript with the AMD wrapper false
commonjs Exports CommonJS style, path to Handlebars module ""
handlebarPath Path to handlebar.js (only valid for amd-style) ""
known Known helpers []
knownOnly Known helpers only false
namespace Template namespace ""
root Template root (base value that will be stripped from template names) ""
data Include data when compiling false
bom Removes the BOM (Byte Order Mark) from the beginning of the templates false
simple Output template function only false
map Generates source maps false

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.

sbt-hbs's People

Contributors

gbicou avatar jchernan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.