Code Monkey home page Code Monkey logo

grunt-dust-html's Introduction

About

This task renders Dust templates against a context to produce HTML.

Getting Started

Install this plugin with the command:

npm install grunt-dust-html

Next, add this line to your project's grunt file:

grunt.loadNpmTasks("grunt-dust-html");

Lastly, add the configuration settings (see below) to your grunt file.

Documentation

This task has two required properties, src and dest. src is the path to your source file and dest is the file this task will write to (relative to the grunt.js file). If this file already exists it will be overwritten.

An example configuration looks like this:

grunt.initConfig({
  dusthtml: {
    dist: {
      src: "src/home.dust",
      dest: "dist/home.html",

      options: {
        // see below for options. this is optional.
      }
    }
  }
});

Optional Configuration Properties

This plugin can be customized by specifying the following options:

  • whitespace (Boolean): Whether or not to preserve whitespace. false by default.
  • partialsDir (String|Array): Path to one or more directories that contain your partials.
  • defaultExt (String): The default template extension of your partials. Defaults to .dust.
  • module (String): The name of the Dust module to use. Defaults to dustjs-linkedin but can also be dust for plain ol' dust, or dustjs-helpers for the LinkedIn Dust build with helpers. If this option is anything other than the default, make sure you have installed the module via npm install.
  • context (Object|String): A JavaScript object to render the template against. This option supports two different types:

String: the location to a file containing valid JSON:

context: "path/to/file.json"

Object: a regular ol' JavaScript object:

context: {
  pageTitle: "My Awesome Website"
}

Array: an array of contexts, either string (files to parse) or JavaScript objects, or both. Each item in the array will be merged into a single context and rendered against the template:

context: [
  "path/to/context.json",
  "path/to/another/context.json",
  { more: "data" }
]

FAQ

  1. Why does the output say undefined?
    Most likely dust is trying to include a file but it can't resove the path properly. Make sure you're setting a basePath option.

Tests

Run npm test.

grunt-dust-html's People

Contributors

ehynds avatar meloncholy avatar ericponto avatar kmartinson avatar thiago avatar spect avatar

Watchers

James Cloos avatar Edward Maesen avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.