Permalink
Browse files

added callback argument to document function

  • Loading branch information...
1 parent 92051d9 commit 6b98d7136429d19abc4a588aa884e2dd203931b2 @neocotic neocotic committed Mar 18, 2013
Showing with 50 additions and 11 deletions.
  1. +33 −6 docco.js
  2. +17 −5 docco.litcoffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -77,25 +77,37 @@ assets, reading all the source files in, splitting them up into prose+code
sections, highlighting each file in the appropriate language, and printing them
out in an HTML template.
- document = (options = {}) ->
+ document = (options = {}, callback) ->
configure options
exec "mkdir -p #{config.output}", ->
- exec "cp -f #{config.css} #{config.output}"
- exec "cp -fR #{config.public} #{config.output}" if fs.existsSync config.public
+ steps = 2
+ completed = 0
+
+ complete = (error) ->
+ if error
+ if _.isFunction callback then return callback error
+ else throw error
+
+ callback?() if ++completed is steps
+
+ exec "cp -f #{config.css} #{config.output}", complete
+ if fs.existsSync config.public
+ steps++
+ exec "cp -fR #{config.public} #{config.output}", complete
files = config.sources.slice()
nextFile = ->
source = files.shift()
fs.readFile source, (error, buffer) ->
- throw error if error
+ complete error if error
code = buffer.toString()
sections = parse source, code
format source, sections
write source, sections
- nextFile() if files.length
+ if files.length then nextFile() else complete()
nextFile()

0 comments on commit 6b98d71

Please sign in to comment.