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

dustin

v1.2.6

Published

An abstraction on LinkedIn's Dust fork with express support

Downloads

30

Readme

dustin

Better templating with LinkedIn's dust fork.

Dustin extends dust with some missing functionality like cache control and formatting option for white space preservation.

It also provides a convenient express engine (dust.__express). This package also includes dustjs-helpers alongside some useful helpers.

Install

npm i dustin --save

Usage

var dustin = require("dustin")
var dust = dustin({
  cache: true,
  views: "/",
  helpers: "helpers/*.js",
  whiteSpace: true
})

cache

If false, every dust.render() will purge the cache. It is especially useful for development, when changes to a template should be reflected in the browser on reload.

views

Partials will resolve to this folder. It helps so you don't have to write full template paths all the time.

helpers

A glob pattern for user helpers to extend the dust.helpers object.

A helper should export a function with one or two arguments:

module.exports = function( helpers, dust ){
  helpers.something = function(chunk, context, bodies, params){}
}

extended API

dust.__express

An express engine.

Hook it to express like this:

var dustin = require("dustin")
var engine = dustin({
  cache: false,
  views: "app/views",
  helpers: "app/helpers/*.js",
  whiteSpace: true
})
app.engine("dust", engine.__express)
app.set("view engine", "dust")
app.set("views", "app/views")
app.set("view cache", false)

getTemplateNameFromPath(path)

Returns a template name according to the options you passed to dustin

getTemplatePathFromName(name)

Returns an absolute path concatenated from the cwd, the template dir you passed to dustin and the name argument with the .dust extension

Copy client libraries

var dustin = require("dustin")
dustin.client("destination folder", "resolve path", {
   dust: true,
   user: "",
   custom: ""
 })

destination

Client side scripts will be copied here.

resolve path

Client templates are loaded like this:

script.src =  /^(https?:)?\/\/?/.test(template)
  ? template
  : ("RESOLVE_PATH" + "/" + template + ".js").replace(/\/+/g, "/")

Set the resolve path to a template root.

Custom helpers

for

Params:

$key:

a variable name for the key. defaults to $key

$value:

a variable for the value. defaults to $value

$in:

the object to iterate over if not provided context.current() will be used

params are prefixed with a $ so it's less likely they clash with context members

@example

Context

"ooo": {
  "a": {
    "1": "1"
  },
  "b": {
    "2": "2"
  }
}

Template

{@for var="asd" value="qwe" $in=ooo}
  {asd}
  {@for:qwe}
    {$key} - {$value} {~n}
  {/for}
{/for}

Output

a1 - 1
b2 - 2

include

Embed a file from the file system into the template.

Params

src

The file's source.

macro

Render a partial's body with the macro's params (except the partial).

Params

partial

The template name of a partial

with

This simply sets the context to the head of the stack. It helps cutting down on typing accessors.

context

"someObject": {
  "a": "hello",
  "b": "hi"
}

template

{@with:someObject}
  {a}{~n}
  {b}
{/with}

Output

hello
hi

Client side extended API

dust.renderElement( template, context, done )

The same as dust.render, but instead of a string it calls done(err, out) with a document fragment.

Licence

MIT