Skip to content

Instantly share code, notes, and snippets.

@hans
Created March 13, 2011 20:44
Show Gist options
  • Save hans/868424 to your computer and use it in GitHub Desktop.
Save hans/868424 to your computer and use it in GitHub Desktop.
A Rake task for compiling CoffeeScripts stored inside the /public/javascripts directory into a single `application.js` JavaScript file. Requires the 'coffee-script' binary (`npm install coffee-script`).
require 'find'
desc 'Compile CoffeeScript files to JavaScript'
task :coffee do
files_to_compile = []
# Find the
Dir.chdir File.join(Rails.root.to_s, 'public', 'javascripts') do
Find.find(Dir.pwd) do |path|
if FileTest.directory? path
if File.basename(path)[0] == ?.
Find.prune
else
next
end
elsif path =~ /\.coffee$/
files_to_compile << path
end
end
File.open 'application.js', 'w' do |js|
js.write `coffee -pj #{files_to_compile.join(' ')}`
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment