Skip to content

Commit

Permalink
handle all docpad events
Browse files Browse the repository at this point in the history
  • Loading branch information
evantill committed Dec 18, 2013
1 parent 97b5079 commit 6cff6a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 59 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docpad-plugin-grunt",
"version": "2.1.1",
"version": "2.1.2",
"description": "Run Grunt tasks when building with DocPad.",
"license": "MIT",
"homepage": "http://github.com/robloach/docpad-plugin-grunt",
Expand Down Expand Up @@ -31,7 +31,8 @@
"grunt": "~0.4.2",
"grunt-cli": "~0.1.10",
"safeps": "~2.2.8",
"glob": "~3.2.7"
"glob": "~3.2.7",
"underscore": "~1.5.2"
},
"devDependencies": {
"coffee-script": "~1.6.2",
Expand Down
75 changes: 18 additions & 57 deletions src/grunt.plugin.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
_ = require('underscore')

# Export Plugin
module.exports = (BasePlugin) ->
# Define Plugin
Expand All @@ -16,8 +18,23 @@ module.exports = (BasePlugin) ->
populateCollectionsBefore: false
populateCollections: false

createEventHandlers: (docpad) ->
events = docpad.getEvents()
_.each events, (eventName) =>
@[eventName] = (opts, next) =>
if tasks = @getConfig()[eventName] or false
@processGrunt(tasks, opts, next)
else
return next()
@
@

# Constructor
constructor: ->
constructor: (opts)->
# create eventHandlers
{docpad} = opts
@createEventHandlers(docpad)

# Prepare
super

Expand All @@ -29,62 +46,6 @@ module.exports = (BasePlugin) ->
# Chain
@

writeBefore: (opts, next) ->
if tasks = @getConfig().writeBefore or false
@processGrunt(tasks, opts, next)
else
return next()
@

writeAfter: (opts, next) ->
if tasks = @getConfig().writeAfter or false
@processGrunt(tasks, opts, next)
else
return next()
@

renderBefore: (opts, next) ->
if tasks = @getConfig().renderBefore or false
@processGrunt(tasks, opts, next)
else
return next()
@

renderAfter: (opts, next) ->
if tasks = @getConfig().renderAfter or false
@processGrunt(tasks, opts, next)
else
return next()
@

generateBefore: (opts, next) ->
if tasks = @getConfig().generateBefore or false
@processGrunt(tasks, opts, next)
else
return next()
@

generateAfter: (opts, next) ->
if tasks = @getConfig().generateAfter or false
@processGrunt(tasks, opts, next)
else
return next()
@

populateCollectionsBefore: (opts, next) ->
if tasks = @getConfig().populateCollectionsBefore or false
@processGrunt(tasks, opts, next)
else
return next()
@

populateCollections: (opts, next) ->
if tasks = @getConfig().populateCollections or false
@processGrunt(tasks, opts, next)
else
return next()
@

# Process the Grunt tasks.
processGrunt: (tasks, opts, next) ->
# Prepare
Expand Down

0 comments on commit 6cff6a7

Please sign in to comment.