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.6.x.
Add the sbt plugin to your project/plugins.sbt
file:
lazy val sbtDustjs = ProjectRef(uri("https://github.com/mebur/sbt-dustjs-linkedin.git"),"sbt-dustjs-linkedin")
lazy val root = project.in(file(".")).dependsOn(sbtDustjs)
Two options are available:
Option | Description |
---|---|
helpers | Loads in DustJs helpers if they are available. |
infoNotice | Show DustJs version number and if helpers are active. |
amdModule | Compile the templates as AMD modules. The templates will require the module 'dust.core' (as compiled by the dust template compile) |
Example:
Assets / DustJsKeys.helpers := true
Assets / DustJsKeys.amdModule := true
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.
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.
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
Add this to your build.sbt
to enabled node compilation - requires node installed on machine.
JsEngineKeys.engineType := JsEngineKeys.EngineType.Node
1.0.7 - March, 2023
- Updated sbt version to 1.6.2
1.0.6 - January 4, 2019
- Cross compiled version
1.0.5 - May 25, 2016
- Added template compiling as AMD module
1.0.4 - May 5, 2016
- Converted to using
package.json
for installing dependencies - Versions can now be adjusted by updating
package.json
- Updated readme example usage
1.0.3 - August 5, 2014
- Add Windows compatibility
1.0.2 - July 9, 2014
- Reverted away from transpiler to have more control
- Fixed source file mapping bug
1.0.1 - July 7, 2014
- Updated to dustjs-linked version 2.4.0
- Added webjar as npm module
- Removed dependency for npm installed dust
1.0.0 - May 19, 2014
- Inital commit
- Added tests using sbt scripted