grunt-new
v0.0.0
Published
Minimal generator. Adds files to existing projects with your choice of templates.
Downloads
2
Readme
grunt-new
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)
.