Skip to content

Commit

Permalink
added callback argument to document function
Browse files Browse the repository at this point in the history
  • Loading branch information
neocotic committed Mar 18, 2013
1 parent 92051d9 commit 6b98d71
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
39 changes: 33 additions & 6 deletions docco.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions docco.litcoffee
Expand Up @@ -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()
Expand Down

0 comments on commit 6b98d71

Please sign in to comment.