Add coffeescript support ? #1

konijn opened this Issue Aug 12, 2011 · 3 comments

2 participants


All you need is add in the beginning

Coffee = require('coffee-script');

And then after var ext = Path.extname(path);

if( ext == ".coffee" )
content = ( eval( Coffee.compile( content+"" , {} ) ) );

The value of the last statement will then be the output, so for this simple coffee script, the content becomes "Tweede".

console.log( "This gets logged" );
return "Tweede";


I don't want to add this directly into the core, because some people may want to actually deliver the content, not the output, but I'll show you an example server that should do what you want. :)

var Trailer = require('trailer'),
    Coffee = require('coffee-script');

Trailer.hitch({ root: "./Web" }).listen(80);

Trailer.scrub['.coffee'] = function (coffee) {
    return Coffee.compile(coffee);
@partheseas partheseas closed this Aug 12, 2011

Thanks !


If you update to 0.7.x, the above code will not work. Instead use..

var trailer, path, coffee;

trailer = require('trailer')
path = require('path')
coffee = require('coffee-script')

trailer.hitch({ root: "./Web" })

trailer.on( "finalized", function ( request, response ) {
    if ( path.extname( request.path ) === ".coffee" )
        response.body = coffee.eval( response.body.toString( whateverEncodingYouSaveYourFilesWith ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment