Skip to content

Commit

Permalink
shortcut method to listen on end event
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo committed Dec 19, 2011
1 parent c8d62bb commit ec7874c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/template.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ class Template extends EventEmitter
end: =>
@xml.end arguments...

ready: (callback) =>
if @xml.closed is yes
callback()
else
@xml.once('end', callback)


# exports

Expand Down
6 changes: 3 additions & 3 deletions src/test/template.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports =
@end()


xml.on 'end', æ.done
xml.ready æ.done
xml.on 'data', (tag) -> æ.equal results.shift(), tag
results = [
'<!DOCTYPE html>'
Expand Down Expand Up @@ -56,7 +56,7 @@ module.exports =
@$title "holla"
@$body ->
@$p "hello world"
xml.on 'end', æ.done
xml.ready æ.done
xml.on 'data', (tag) -> æ.equal results.shift(), tag
results = [
'<!DOCTYPE html>\n'
Expand Down Expand Up @@ -95,7 +95,7 @@ module.exports =
title:'test'
content:'..'

xml.on 'end', æ.done
xml.ready æ.done
xml.on 'data', (tag) -> æ.equal results.shift(), tag
results = [
'<html>'
Expand Down

0 comments on commit ec7874c

Please sign in to comment.