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

grunt-dustjs

v1.4.0

Published

Grunt task to compile Dust.js templates.

Downloads

2,447

Readme

grunt-dustjs

Grunt task to compile Dust.js templates.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-dustjs.

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-dustjs');

Documentation

Inside your grunt.js file, add a section named dustjs with one or more targets. Each section contains a files object that specifies the Dust.js template files to compile.

files object

This defines what files this task will process. It can contain any valid Grunt files format.

When using a src/dest format, the key (destination) should be an unique filepath (supports grunt.template) and the value (source) should be a filepath or an array of filepaths (supports minimatch). All source files will be combined into the destination output.

When using the dynamic format (example #3), each source file will be processed into its own destination file.

Options

fullname default: false

Used to customize the template variable names. If fullname is true, the full path will be used as the template name. If fullname is a function, the function receives a single argument, which is the full path, and returns the name of the template.

transformQuote default: false

Used to reverse quotes usage by dustjs: double quotes replaced by single quotes and vice versa. Output is more clean after this transformation.

prepend default: null

Add a custom string to the start of the output file. This is useful for creating custom AMD wrappers, eg: define(['dust'], function(dust){\n

append default: null

Add a custom string to the end of the output file.

whitespace default: false

Preserve whitespace.

amd default: false

Compile as AMD modules.

cjs default: false

Compile as CommonJS modules.

silent default: false

Suppress success compile messages.

Example #1

module.exports = function (grunt) {
  //...
  grunt.loadNpmTasks('grunt-dustjs');
  //...

  var config = {
    //...
    dustjs: {},
    //...
  };

  config.dustjs: {
    compile: {
      files: {
        'js/templates.js': ['src/templates/**/*.html']
      }
    }
  },
});

Example #2 (custom template names)

var path = require('path');

module.exports = function (grunt) {
  //...
  grunt.loadNpmTasks('grunt-dustjs');
  //...

  var config = {
    //...
    dustjs: {},
    //...
  };

  config.dustjs: {
    compile: {
      files: {
        'js/templates.js': ['src/templates/**/*.html']
      },
      options: {
        fullname: function(filepath) {
          var key = path.relative('src/templates', path.dirname(filepath)).split(path.sep) // folder names
            .concat([path.basename(filepath, path.extname(filepath))]) // template name
            .join('.');

          if (key.charAt(0) == '.')
            return key.substr(1, key.length - 1);
          return key;
        }
      }
    }
  },
});

Example #3 (one JS file per template)

module.exports = function (grunt) {
  //...
  grunt.loadNpmTasks('grunt-dustjs');
  //...

  var config = {
    //...
    dustjs: {},
    //...
  };

  config.dustjs: {
    compile: {
      files: [
        {
          expand: true,
          cwd: 'dust/',
          src: '**/*.html',
          dest: '',
          ext: '.js'
        }
      ]
    }
  }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

  • 30/01/2016 - 1.3.0: Support 2.7.x options, silent option
  • 07/02/2014 - 1.2.1: Update jshint
  • 14/01/2014 - 1.2.0: Add append/prepend wrapper strings (@kreegr), error handling (@sunflowerdeath)
  • 23/07/2013 - 1.1.0: Introduce transformQuote option.
  • 23/07/2013 - 1.0.1: Correct expand function.
  • 18/07/2013 - 1.0.0: Release.
  • 18/07/2013 - 0.2.4: Update examples.
  • 19/01/2013 - 0.2.2: Grunt v0.4rc5 compatibility (@toddself).
  • 14/12/2012 - 0.2.1: Grunt v0.4 compatibility (@SpeCT).
  • 08/12/2012 - 0.2.0: Add namespace support (@bernharduw).
  • 25/09/2012 - 0.1.2: Initial release.

License

Copyright (c) 2013-2016 Stanislav Lesnikov Licensed under the MIT license.