Any obvious reference to coffee needs a picture |
Well the answer is to compile to JS at runtime. However, I had an awful time getting the right setup to get going. If you are interested in playing with CoffeeScript where Node.js is not available (I'm using it in work to show what it's capable of) then just follow these instructions.
Create a directory to work in and inside that create an index.html file thus:
<!DOCTYPE html> <html> <head> <title>CoffeeScript Demo</title> <script data-main="scripts/requirements" src="scripts/require.js"></script> </head> <body> <h1>CoffeeScript Demo</h1> </body> </html>
and a directory called 'scripts' into which you put the following.
- JQuery
- Require
- CoffeeScript Plugin For Require
- A file called requirements.js containing:
require([ 'scripts/jquery-1.6.1.min.js', 'cs', 'cs!app', ]);
- And a file called app.coffee containing:
square = (x) -> x * x alert square 42
That's it!
Now load the index.html page into your browser and the CoffeeScript code app.coffee should execute.
Of course you will now have to go away and read the docs so that you know why that worked, but then so will I.
No comments:
Post a Comment