Thursday, March 15, 2012

Compile Coffeescript to Javascript

Many friends not familiar with coffeescript yet, but Rails 3.2 is already generating coffee script by default when you do scaffold. So far it is OK for them to achieve something by "copy and paste" from internet. However, it is hard for them to modify the script they got.


So, one way is ... use Javascript by changing the extension from .js.coffee to .js. But human has to learn, right? Here is the second way: learn by comparing coffee script and javascript implemtation.


Compile CoffeeScript to Javascript inside Aptana Studio

[Commands] -> [CoffeeScript] -> [Run] -> [Compile and Display JS]

a corresponding .js file will be generated and then you can see how each line of coffee script is compiled into javascript.



if there is error saying coffee command not found, just go ahead and install coffee-script library for your OS.

e.g. in MacOSX, brew install coffee-script