Skip to content

Commit

Permalink
Merge pull request #167 from neocotic/async-support
Browse files Browse the repository at this point in the history
Callback
  • Loading branch information
jashkenas committed Mar 19, 2013
2 parents 92051d9 + ab08a11 commit 0b4678f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
32 changes: 24 additions & 8 deletions docco.js

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

15 changes: 10 additions & 5 deletions docco.litcoffee
Expand Up @@ -77,25 +77,30 @@ 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
callback or= (error) -> throw error if error
complete = ->
exec [
"cp -f #{config.css} #{config.output}"
"cp -fR #{config.public} #{config.output}" if fs.existsSync config.public
].join(' && '), callback
files = config.sources.slice()
nextFile = ->
source = files.shift()
fs.readFile source, (error, buffer) ->
throw error if error
return callback 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 0b4678f

Please sign in to comment.