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.
-
Documentation: sinefunc.com/sinatra-support
- {Sinatra::CssSupport}
-
Provides CSS/Sass/Less support.
- {Sinatra::JsSupport}
-
Provides JavaScript/CoffeeScript support.
- {Sinatra::Numeric}
-
Helpers for showing percentages and currencies.
- {Sinatra::DateForms}
-
Provides dropdowns for year/month/date.
- {Sinatra::I18nSupport}
-
Provides I18n support.
- {Sinatra::MultiRender}
-
Allow rendering from multiple view paths and auto-guessing template engines.
- {Sinatra::CompassSupport}
-
Adds support for the Compass CSS framework.
- {Sinatra::CompressedJS}
-
JavaScript compression.
- {Sinatra::AppModule}
-
Write parts of your application as a module.
- {Sinatra::CountryHelpers}
-
Country dropdowns and stuff.
- {Sinatra::HtmlHelpers}
-
Provides many common HTML helpers.
- {Sinatra::IfHelpers}
-
Common HAML condition helpers.
- {Sinatra::UserAgentHelpers}
-
Browser detection.
- {Sinatra::OhmErrorHelpers}
-
Allows you to present errors nicely in HAML templates.
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 end
Detect browser versions easily.
helpers Sinatra::UserAgentHelpers if browser.ios? && !browser.ipad? redirect '/touch' end
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)
Conditional helpers for HAML (checked_if
, hide_if
, etc):
%input{checked_if(page.available?), type: 'checkbox'} %div#comments{hide_if(post.comments.empty?)}
<select name="country"><%= select_options country_choices %></select>
<select name="birthday[month]"><%= month_choices %></select> <select name="birthday[day]"><%= day_choices %></select> <select name="birthday[year]"><%= year_choices %></select>
<%= currency(100) %><!-- $100 --> <%= percentage(100) %><!-- 100.00% -->
<%= h "<Bar>" %> <select name="categories"> <%= select_options [['First', 1], ['Second', 2]] %> </select>
Also consider Rico Sta. Cruz’s sinatra-template which already preloads some of Sinatra Support’s conveniences and more. github.com/rstacruz/sinatra-template
Copyright © 2009-2011 Cyril David, Rico Sta. Cruz and Sinefunc, Inc. See LICENSE for details.