sinatra with bourbon

posted by alexis reigel on march 24, 2012

If you search the web for “bourbon sinatra” you get a whole lot about Frank Sinatra and his drinking habits. But that’s not what this post is about.

How to use bourbon scss mixins with sinatra is not documented on their project page. So here’s my short setup.

The following is standard, from their documentation.

$ gem install bourbon # or better, add to use Gemfile and use bundler
$ cd views/scss
$ bourbon install

Next, import bourbon in your main scss file (as first statement).

@import 'bourbon/bourbon';

The following is the important and the undocumented part, specifically for sinatra. You need to require the ruby libraries in your scss route.

get '/assets/css/:name.scss' do |name|
  require './views/scss/bourbon/lib/bourbon.rb'
  content_type :css 
  scss name.to_sym, :layout => false

sinatra on capistrano

posted by alexis reigel on january 31, 2012

Capistrano is really great for deployment. The documentation however is somewhat scattered. The capistrano wiki has a more or less useful From The Beginning instruction and a Getting Started that doesn’t quite get you started.
However, the instructions on github are actually a very good starting point. Neverthelesse I want to show my sample here that has two additions to the one in the github help.

  1. Multistage support (i.e. staging and production server)
  2. Custom task to upload a config file

For further reading I recommend the Capistrano Handbook.

I assume that you’ve setup capistrano as described in the github help. The one thing I suggest is to ignore the part where the password is stored in the file. I highly advise to use ssh agent forwarding instead.

ssh_options[:forward_agent] = true # use local ssh key
set :user, "deployer"

Let’s setup multistage:

require 'capistrano/ext/multistage'
set :stages, %w(production staging)
set :default_stage, "staging"

Also, on most deployment server you may not have rights to sudo:

set :use_sudo, false

As I’m assuming you’re using passenger mod_rails:

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

The last part uploads our configuration file to the server. This configuration contains user and password for the database login. We don’t store that in the source code repository.

namespace :config do
  task :db do
    upload('db.yml', "#{deploy_to}/current/db.yml")

before "deploy:restart", "config:db"

The whole capistrano configuration file is on github.