CoffeeScript In Sinatra
First you need to install some gems:
%> gem install coffee-script therubyracer
Now open up your text editor and we’ll create a little demo app all in one file:
require 'sinatra' require 'slim' require 'v8' get '/application.js' do coffee :script end get '/' do @title = "CoffeeScript in Sinatra" slim :index end __END__ @@layout doctype html html head meta charset="utf-8" title @title script src="/application.js" body == yield @@index h1 @title @@script alert 'Coffeescript is working.'
That’s how simple it is!