klei-dust is a helper (inspired by Consolidate) to use dustjs-linkedin templates as views along with express for node.js.
The main advantage with klei-dust is that it supports relative paths for partials and base templates.
E.g. you can have a base template base.dust at /views/base.dust and a child template at /views/child.dust with the following contents:
file: /views/base.dust
<!DOCTYPE html>
<html>
<head>
<title>A title here</title>
</head>
<body>
{+content/}
</body>
</html>file: /views/child.dust
{>base/}
{<content}
<p>Child content...</p>
{/content}And child views in subfolders:
file: /views/subviews/child2.dust
{>"../base"/}
{<content}
<p>Sub child content...</p>
{/content}See root and relativeToFile options below for alternatives.
$ npm install klei-dust
N.B. You must install dustjs-linkedin as well.
To use dust as your default template file extension use:
var express = require('express'),
kleiDust = require('klei-dust'),
app = express();
app.configure(function () {
...
app.set('views', __dirname + '/views');
app.engine('dust', kleiDust.dust);
app.set('view engine', 'dust');
app.set('view options', {layout: false});
...
});
...If you want another extension, e.g. html then use this settings instead:
...
kleiDust.setOptions({extension: 'html'}); // Add the extension option
app.set('views', __dirname + '/views');
app.engine('html', kleiDust.dust); // change engine to the same filetype
app.set('view engine', 'html'); // ditto
app.set('view options', {layout: false});
...N.B. In the examples above klei-dust uses the express views setting to locate views, see options below.
How to use klei-dust to compile templates whithout express:
var kleiDust = require('klei-dust');
kleiDust.dust('<your-template-folder>/<your-template-name>', <template-data>, function (err, out) {
if (err) return console.log(err);
// Do something with `out`...
});relativeToFile- specifies if paths to partials, base templates, etc. should be specified relative to the current view or to the views root folder, defaults totrueroot- sets the root directory for all the views/templates, if not set the expressviewssetting is used (only applies ifrelativeToFileis set tofalse)extension- sets the default extension for views if omitted in includes/partials, defaults to.dustcache- specifies if the template cache should be enabled or not, defaults tofalsekeepWhiteSpace- iftruewhitespace in templates won't be compressed, defaults tofalseuseHelpers- iftrueklei-dust will try and load dustjs-helpers, defaults tofalse
The options is set with the setOptions() method.
getDust- returns the dustjs-linkedin instance to be able to use the streaming api and such.setHelpers- sets the dust.helpers property to the given value.getHelpers- gets the current dust.helpers.setFilters- sets the dust.filters property to the given value.getFilters- gets the current dust.filters.create- create a new instance
MIT