Skip to content

Instantly share code, notes, and snippets.

@gonzedge
Created November 11, 2011 03:56
Show Gist options
  • Save gonzedge/1357146 to your computer and use it in GitHub Desktop.
Save gonzedge/1357146 to your computer and use it in GitHub Desktop.
The joy of writing CoffeeScript
class BuildUtils
combine_source_files: (callback) ->
self = @
fs.readdir './src', (err, files) ->
self.error_handler err
content = new Array()
files = files.sort()
for file, index in files when file.indexOf('.') isnt 0 then do (file, index) ->
fs.readFile "./src/#{file}", 'utf8', (err, fileContent) ->
self.error_handler err
content[content.length] = fileContent
if index is files.length - 1
callback content
class BuildUtils
combine_source_files: (callback) ->
self = @
fs.readdir './src', (err, files) ->
self.error_handler err
content = new Array()
files = files.sort()
for file, index in files then do (file, index) ->
unless file.indexOf('.') is 0
fs.readFile "./src/#{file}", 'utf8', (err, fileContent) ->
self.error_handler err
content[content.length] = fileContent
if index is files.length - 1
callback content
for file, index in files when file.indexOf('.') isnt 0 then do (file, index) ->
# The code I want to run
for file, index in files then do (file, index) ->
unless file.indexOf('.') is 0
# The code I want to run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment