Home

Awesome

sbt-dustjs-linkedin

Build Status

An SBT plugin to compile Dustjs templates.

This plugin is a continuation of play-dustjs built for sbt-web and Play 2.3.x - Play 2.5.x.

Installation

Add the sbt plugin to your project/plugins.sbt file:

addSbtPlugin("com.jmparsons.sbt" % "sbt-dustjs-linkedin" % "1.0.5")

Two options are available:

OptionDescription
helpersLoads in DustJs helpers if they are available.
infoNoticeShow DustJs version number and if helpers are active.
amdModuleCompile the templates as AMD modules. The templates will require the module 'dust.core' (as compiled by the dust template compile)

Example:

DustJsKeys.helpers in Assets := true
DustJsKeys.amdModule in Assets := true

Usage

Install mkdirp, dustjs-linked and optionally dustjs-helpers for node

Add package.json to base folder of project and run npm install to load in node dependencies.

{
  "name": "sbt-dust-tester",
  "version": "0.0.0",
  "dependencies": {
    "mkdirp": "~0.5.0",
    "dustjs-linkedin": "2.7.2",
    "dustjs-helpers": "1.7.3"
  }
}

Versions can be updated here, but should match the webjar bower versions.

Install dustjs-linked and optionally dustjs-helpers bower webjars

Include the corresponding versioned dust files as the node dependencies:

libraryDependencies ++= Seq(
  "org.webjars.bower" % "dustjs-linkedin" % "2.7.2",
  "org.webjars.bower" % "dustjs-helpers" % "1.7.3"
)

Newer versions can be added quickly using the add new webjar at bower webjars.

The dust files can also be added manually in the public folder from LinkedIn Dustjs.

Render your templates

Place your template .tl files anywhere inside of the app/assets/ it will be available in the corresponding directory. If placed into app/assets/templates/ the output would be target/web/public/main/templates/.

RequireJS example:

require.config
  paths:
    jquery: "../lib/jquery/jquery"
    dust: "../lib/dustjs-linkedin/dist/dust-full"
    dustHelpers: "../lib/dustjs-helpers/dist/dust-helpers"
    testTemplate: "../templates/test"
  shim:
    jquery:
      exports: "$"
    dustHelpers:
      deps: ["dust"]
    testTemplate:
      deps: ["dust", "dustHelpers"]

require ["jquery", "testTemplate"], ->
  $ ->
    $.get "/data", (data) ->
      dust.render "templates/test", data, (err, out) ->
        $("#dust_pan").html (if err? then err else out)

Javascript example:

<script src="@routes.Assets.at("lib/jquery/jquery.js")"></script>
<script src="@routes.Assets.at("lib/dustjs-linkedin/dist/dust-core.js")"></script>
<script src="@routes.Assets.at("lib/dustjs-helpers/dist/dust-helpers.js")"></script>
<script src="@routes.Assets.at("templates/test.js")"></script>
<script>
$(function() {
  $.get('@(routes.Application.data)', function(data) {
    console.log('data = ' + JSON.stringify(data));
    dust.render('templates/test', data, function(err, out) {
      $('#dust_pan').html(err ? err : out);
    });
  });
});
</script>

Example project with RequireJS using play-dustjs: https://github.com/jmparsons/play-scala-backbone-todo

Speed up compilation using node

Add this to your build.sbt to enabled node compilation - requires node installed on machine.

JsEngineKeys.engineType := JsEngineKeys.EngineType.Node

Changelog

1.0.5 - May 25, 2016

1.0.4 - May 5, 2016

1.0.3 - August 5, 2014

1.0.2 - July 9, 2014

1.0.1 - July 7, 2014

1.0.0 - May 19, 2014

License

MIT: http://jmparsons.mit-license.org - @jmparsons