Generate the documentation for a source file by reading it in, splitting it
up into comment/code sections, highlighting them for the appropriate language,
and merging them into an HTML template.
generateDocumentation = (source, config, callback) ->
fs.readFile source, (error, buffer) ->
throw error if error
code = buffer.toString()
sections = parse source, code, config
highlight source, sections, config, ->
generateHtml source, sections, config
callback()
document = (sources, options = {}, callback = null) ->
config = {}
config[key] = defaults[key] for key,value of defaults
config[key] = value for key,value of options if key of defaults
config.sources = sources.filter((source) -> getLanguage source, config).sort()
console.log "docco: skipped unknown type (#{m})" for m in sources when m not in config.sources
config.doccoTemplate = _.template fs.readFileSync(config.template).toString()
doccoStyles = fs.readFileSync(config.css).toString()
ensureDirectory config.output, ->
fs.writeFileSync path.join(config.output,path.basename(config.css)), doccoStyles
files = config.sources.slice()
nextFile = ->
callback() if callback? and not files.length
generateDocumentation files.shift(), config, nextFile if files.length
nextFile()