Tim Riley

Cleaner Sinatra integration with Compass 0.4

February 15th 2009

Chris Eppstein has been working hard on Compass lately to improve its integration with application frameworks. This gives me the pleasure of updating the code from my earlier post about integrating Sinatra and Compass:

gem 'chriseppstein-compass', '~> 0.4'
require 'compass'

configure do
  Compass.configuration do |config|
    config.project_path = File.dirname(__FILE__)
    config.sass_dir     = File.join('views', 'stylesheets')
  end
end

get "/stylesheets/screen.css" do
  content_type 'text/css'

  # Use views/stylesheets & blueprint's stylesheet dirs in the Sass load path
  sass :"stylesheets/screen", :sass => Compass.sass_engine_options
end

The above is everything you need for your Sinatra app to use Compass 0.4 to render your CSS. The biggest change in 0.4 is that Compass now comes with a configuration singleton. I set it up above in Sinatra’s configure block and tell it that I keep my Sass stylesheets in views/stylesheets inside the application directory. Keeping the Sass configuration separate from the working application code keeps your render calls short and concise, like the rest of your well-crafted Sinatra app.

Thanks to Chris for his hard work and for providing the example code for the Sinatra integration.

Tim Riley

Hi, I'm Tim Riley. I'm a web developer based in Canberra, Australia, where I work at a small design studio called Icelab. This is my blog, where I can share with you the things I learn as I go about building products for the web.

What I Build

Recent Presentations

  1. Facebook Authentication with OAuth
  2. JavaScript Testing with Capybara and Cucumber
  3. Using Titanium to Build Mobile Apps with JavaScript (audio)
  4. An Introduction to Sinatra
  5. Building your Capistrano Recipe Book