Bare metal helpers for your sinatra app
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Sinatra Support

A collection of useful utilities.

Sinatra Support's mission is to implement the things web apps will need 90% of the time. Think of it as Rails's conveniences done the Sinatra way.



Provides CSS/Sass/Less support.


Provides JavaScript/CoffeeScript support.


Helpers for showing percentages and currencies.


Provides dropdowns for year/month/date.


Provides I18n support.


Allow rendering from multiple view paths and auto-guessing template engines.


Adds support for the Compass CSS framework.


JavaScript compression.


Write parts of your application as a module.



Country dropdowns and stuff.


Provides many common HTML helpers.


Common HAML condition helpers.


Browser detection.


Allows you to present errors nicely in HAML templates.

How to use

Require the Sinatra support gem. For those using Bundler, that is:

# Gemfile
gem "sinatra-support", require: "sinatra/support"

Or otherwise:

# gem install sinatra-support
require 'sinatra/support'

In your Sinatra application, use register or helpers to add in plugins as you need them.

class Main < Sinatra::Base
  register Sinatra::DateForms
  helpers  Sinatra::HtmlHelpers
  helpers  Sinatra::CountryHelpers

Common examples

Provided by {Sinatra::UserAgentHelpers}:

Detect browser versions easily.

helpers Sinatra::UserAgentHelpers

if browser.ios? && !browser.ipad?
  redirect '/touch'

Provided by {Sinatra::CssSupport}:

Serve up dynamic stylesheets (Sass/Less) with ease. Dynamic JavaScript files (CoffeeScript) are also available via {Sinatra::JsSupport}.

register Sinatra::CssSupport
serve_css '/css', from: './app/css'

# curl "http://localhost:4567/css/print.css"   # reads app/css/print.sass 
                                               # (or .less, .scss, .css)

Provided by {Sinatra::IfHelpers}:

Conditional helpers for HAML (checked_if, hide_if, etc):

%input{checked_if(page.available?), type: 'checkbox'}

Provided by {Sinatra::CountryHelpers}:

<select name="country"><%= select_options country_choices %></select>

Provided by {Sinatra::DateForms}:

<select name="birthday[month]"><%= month_choices %></select>
<select name="birthday[day]"><%= day_choices %></select>
<select name="birthday[year]"><%= year_choices %></select>

Provided by {Sinatra::Numeric}:

<%= currency(100) %><!-- $100 -->
<%= percentage(100) %><!-- 100.00% -->

Provided by {Sinatra::HtmlHelpers}:

<%= h "<Bar>" %>

<select name="categories">
  <%= select_options [['First', 1], ['Second', 2]] %>

Starting a new project?

Also consider Rico Sta. Cruz's sinatra-template which already preloads some of Sinatra Support's conveniences and more.


Copyright © 2009-2011 Cyril David, Rico Sta. Cruz and Sinefunc, Inc. See LICENSE for details.