0.0.0 • Published 11 years ago

grunt-new v0.0.0

Weekly downloads
1
License
-
Repository
github
Last release
11 years ago

grunt-new Build Status

Minimal generator. Add files to existing projects. Mix and match template engines. Anything supporting the Consolidate.js signaute 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)

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?'
        }], (err, {title}={}) ->
          # timestamp the new post filename
          date = grunt.template.today 'yyyy-mm-dd'
          slug = grunt.utils._.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).