Using Rails 3.2 (or 3.1 for that matter), you typically have CoffeeScript (and a javascript engine like therubyracer/V8) installed as gems - probably via Bundler from your Gemfile, possibly in a per-project RVM gemset.
It doesn’t seem that this type of setup includes direct access to the coffee
command-line compiler. Instead the coffee-script
gem uses calls directly to the compiler. Sometimes I’d just like to compile one of the CoffeeScript files in my Rails app just to look at the javascript, or maybe to export it somewhere that I’m not using CoffeeScript.
To do this, I’ve made a simple Rake task. Just drop this into lib/tasks/coffee.rake
in your Rails project:
1 2 3 4 5 6 |
|
Then, you can compile a single file from like this:
1
|
|
This will output it to stdout so you can redirect that to a file, or the gist
command, or whatever.