Skip to content

Commit

Permalink
Merge 41822d5 into 4d7016d
Browse files Browse the repository at this point in the history
  • Loading branch information
dapetcu21 committed May 9, 2014
2 parents 4d7016d + 41822d5 commit c424e68
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
docs/_build
.*.sw*
10 changes: 10 additions & 0 deletions lib/api/compile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Compile
.with(@)
.tap(create_folders)
.then(process_files)
.then(after_ext_hook)
.then(after_hook)
.then(purge_empty_folders)
.then(@roots.emit.bind(@roots, 'done'), @roots.emit.bind(@roots, 'error'))
Expand All @@ -75,6 +76,15 @@ class Compile
after_hook = (ast) ->
hook_method.call(@, @roots.config.after)

###*
* Calls any extension-provided after hooks with the roots context.
*
* @private
###

after_ext_hook = ->
sequence(@extensions.hooks('project_hooks.after'), @)

###*
* Checks to ensure the requested hook(s) is/are present, then calls them,
* whether there was an array of hooks provided or just a single hook.
Expand Down
12 changes: 8 additions & 4 deletions lib/extensions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Extensions
if not_function(ext.compile_hooks)
@roots.bail(125, 'The compile_hooks property must be a function', ext)

if not_function(ext.project_hooks)
@roots.bail(125, 'The project_hooks property must be a function', ext)

if not_function(ext.category_hooks)
@roots.bail(125, 'The category_hooks property must be a function', ext)

Expand Down Expand Up @@ -101,10 +104,11 @@ class Extensions
if typeof called_namespace isnt 'object'
@[@length-2].roots.bail(125, "#{namespc} should return an object", ext)

if called_namespace.category
if called_namespace.category isnt category then return
else
if ext.category and ext.category isnt category then return
if category?
if called_namespace.category
if called_namespace.category isnt category then return
else
if ext.category and ext.category isnt category then return

called_namespace[key]

Expand Down
18 changes: 18 additions & 0 deletions test/extensions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe 'extension hooks', ->
.on('after_pass', => @after_pass = true)
.on('write', => @write = true)
.on('after_category', => @after_category = true)
.on('after_project', => @after_project = true)
.on('done', -> done())

@project.compile()
Expand All @@ -50,6 +51,9 @@ describe 'extension hooks', ->
it 'after category hook should work', ->
@after_category.should.be.ok

it 'after project hook should work', ->
@after_project.should.be.ok

describe 'write hook', ->

before (done) ->
Expand Down Expand Up @@ -189,6 +193,20 @@ describe 'extension failures', ->

project.compile()

# this should not throw
it 'should bail when project_hooks is defined but not a function', ->
project = new Roots(path.join(@path, 'case11'))
(-> project.compile()).should.throw('The project_hooks property must be a function')

it 'should bail when project_hooks is a function but doesnt return an object', (done) ->
project = new Roots(path.join(@path, 'case12'))

project.on 'error', (err) ->
err.toString().should.equal('Malformed Extension: project_hooks should return an object')
done()

project.compile()

it 'should bail if write hook returns anything other than an array, object, or boolean', (done) ->
project = new Roots(path.join(@path, 'case9'))

Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/extensions/basic/test_extension.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ module.exports = ->
category_hooks: ->
after: (ctx, category) ->
ctx.roots.emit('after_category', ctx.path)

project_hooks: ->
after: (ctx) ->
ctx.roots.emit('after_project', ctx.path)
6 changes: 6 additions & 0 deletions test/fixtures/extensions/failures/case11/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ext = ->
class Fail7
project_hooks: 'wow'

module.exports =
extensions: [ext()]
Empty file.
6 changes: 6 additions & 0 deletions test/fixtures/extensions/failures/case12/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ext = ->
class Fail8
project_hooks: -> true

module.exports =
extensions: [ext()]

0 comments on commit c424e68

Please sign in to comment.