Klei Dust
klei-dust is a helper (inspired by Consolidate) to use dustjs-linkedin templates as views along with express for node.js.
Advantages
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
A title here {+content/}
file: /views/child.dust
{>base/} {Child content...{/content}
And child views in subfolders:
file: /views/subviews/child2.dust
{>"../base"/} {Sub child content...{/content}
See root
and relativeToFile
options below for alternatives.
Installation
$ npm install klei-dust
N.B. You must install dustjs-linkedin as well.
Setting up Klei Dust with Express
To use dust
as your default template file extension use:
var express = kleiDust = app = ; app;...
If you want another extension, e.g. html
then use this settings instead:
... kleiDust; // Add the extension option app; app; // change engine to the same filetype app; // ditto app; ...
N.B. In the examples above klei-dust uses the express views
setting to locate views, see options below.
Using klei-dust without express
How to use klei-dust to compile templates whithout express:
var kleiDust = ; kleiDust;
Available options
relativeToFile
- specifies if paths to partials, base templates, etc. should be specified relative to the current view or to the views root folder, defaults totrue
root
- sets the root directory for all the views/templates, if not set the expressviews
setting is used (only applies ifrelativeToFile
is set tofalse
)extension
- sets the default extension for views if omitted in includes/partials, defaults to.dust
cache
- specifies if the template cache should be enabled or not, defaults tofalse
keepWhiteSpace
- iftrue
whitespace in templates won't be compressed, defaults tofalse
useHelpers
- iftrue
klei-dust will try and load dustjs-helpers, defaults tofalse
The options is set with the setOptions()
method.
Convenience methods
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
License
MIT