Skip to content
Minimal generator. Adds files to existing projects with your choice of templates.
CoffeeScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
tasks
test
.gitignore
.travis.yml
Gruntfile.coffee
README.md
package.json

README.md

grunt-new Build Status

Minimal generator. Add files to existing projects. Mix and match template engines. Anything supporting the Consolidate.js signature will do.

npm install --save-dev grunt-new

Given a template file like templates/post.hbs:

---
title: {{title}}
author: {{author}}
---

You can do something real basic like

grunt.loadNpmTasks('grunt-new');

grunt.initConfig({
  'new': {
    options: {
      engine: consolidate.handlebars
    }
    post: {
      template: 'templates/post.hbs',
      data: {
        title: 'Placeholder title',
        author: 'Your name here',
        dest: 'src/posts/my-new-post.md'
      }
    },
  },
})

Or something fancy like

pkg = require './package.json'
require('normalize-package-data')(pkg)
inquirer = require 'inquirer'

grunt.loadNpmTasks 'grunt-new'

grunt.initConfig
  new:
    options:
      engine: consolidate.handlebars
    post:
      template: 'templates/post.hbs',
      data: (done) ->
        # prompt the user for the title of the new post
        inquirer.prompt [name: 'title', message: 'Title?'], ({title}) ->
          # timestamp the new post filename
          date = grunt.template.today 'yyyy-mm-dd'
          slug = grunt.util._.dasherize title.toLowerCase()
          done null,
            title: title
            author: pkg.author.name # grab the author name from package.json
            dest: "src/#{date}/#{slug}.md"

Options

engine

Type: Function Default value: _.template

A function that implements the Consolidate.js signature: function(path, data, callback) and calls its callback with (err, string).

Something went wrong with that request. Please try again.