npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

klei-dust

v1.0.0

Published

A helper to use dustjs-linkedin along with Express

Downloads

64

Readme

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

<!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.

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 = 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.

Using klei-dust without express

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`...
});

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 to true
  • root - sets the root directory for all the views/templates, if not set the express views setting is used (only applies if relativeToFile is set to false)
  • 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 to false
  • keepWhiteSpace - if true whitespace in templates won't be compressed, defaults to false
  • useHelpers - if true klei-dust will try and load dustjs-helpers, defaults to false

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