bcobb / mustache-render

Grunt plugin for testing mustache templates

Home Page:http://blog.the5thwall.net/mustache-render

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

grunt-mustache-render v1.1.0

Render mustache templates

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-mustache-render --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-mustache-render');

The "mustache_render" task

Overview

In your project's Gruntfile, add a section named mustache_render to the data object passed into grunt.initConfig().

grunt.initConfig({
  mustache_render: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

File lists must be in the following format:

files: [
  {data: "path/to/data/file.json",
   template: "path/to/template.mustache",
   dest: "file/to/output.html"}
]

Each object in the file array represents one rendered template. Data files can be in either JSON or YAML format.

Options

options.directory

Type: String
Default value: ""

A folder path where partials can be found.

options.extension

Type: String
Default value: ".mustache"

The extension used by partials.

options.prefix

Type: String
Default value: ""

A common prefix for all partials. So given the prefix: part_ for a partial named hello it will search for a file named part_hello.mustache.

options.clear_cache

Type: Boolean
Default value: false

Clears the mustache cache before running the task. Usefull if options.extension, options.directory, or options.prefix have been changed between tasks.

Usage Examples

For this Grunt config:

grunt.initConfig({
  mustache_render: {
    files: [{
      data: "data/hello_world.json",
      template: "templates/hello_world.mustache",
      dest: "public/hello_world.html"
    }],
  },
})

And this json:

{
  "greeting" : "Hello",
  "target" : "World"
}

This template:

<html>
<head>
  <meta charset="UTF-8">
  <title>A greeting</title>
</head>
<body>
  <h1>{{greeting}}, {{target}}!</h1>
</body>
</html>

Will produce this output:

<html>
<head>
  <meta charset="UTF-8">
  <title>A greeting</title>
</head>
<body>
  <h1>Hello, World!</h1>
</body>
</html>

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

1.1.0

  • Option for common prefix on partials
  • Option to clear mustache cache before running task

1.0.0

  • Created website
  • API now considered stable

0.3.0

  • Unverbosify options

0.2.1

  • Bugfix: dependencies

0.2.0

  • YAML data file support

0.1.0

  • Initial Release

About

Grunt plugin for testing mustache templates

http://blog.the5thwall.net/mustache-render

License:MIT License


Languages

Language:JavaScript 100.0%