Find file
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (65 sloc) 3.38 KB
title layout
Sinatra: Extensions in the Wild

Extensions in the Wild

Extensions provide helper or class methods for Sinatra applications. These methods are customarily listed and described on extensions home pages.

Before we use a method provided by the particular an extension, the gem which implements it has to be installed. For example, to install the sinatra-prawn gem available from the, type and run the following command:

gem install sbfaulkner-sinatra-prawn -s

where sbfaulkner is the login of the extension author.

To use the above extension in a Sinatra application, the following lines needs to be inserted into the application code:

gem 'sbfaulkner-sinatra-prawn'
require 'sinatra/prawn'

We can take advantage of RubyGems ability to use versioned libraries at runtime:

gem 'sbfaulkner-sinatra-prawn', '~>0.9.0'

We request the latest installed version of sinatra-prawn gem in the 0.9.x series. If no such gem is installed, an exception is thrown.

If the most current version is not appropriate we can ask for specific one we need:

gem 'sbfaulkner-sinatra-prawn', '=0.9.1'

Note, that we require sinatra/prawn rather than sbfaulkner-sinatra-prawn.

Extensions which provide helper methods

  1. sinatra-prawn adds support for pdf rendering with Prawn templates.
  2. sinatra-markaby enables rendering of html files using markaby templates.
  3. sinatra-maruku provides Maruku templates for a Sinatra application.
  4. sinatra-rdiscount provides RDiscount templates for a Sinatra application.
  5. sinatra-effigy provides Effigy templates and views for a Sinatra application.
  6. sinatra-content-for provides content_for helper similar to Rails one.
  7. sinatra-url-for construct absolute paths and full URLs to actions in a Sinatra application
  8. sinatra-static-assets implements image_tag, stylesheet_link_tag, javascript_script_tag and link_tag helpers. These helpers construct correct absolute paths for applications dispatched to sub URI.
  9. sinatra-mapping implements map in the DSL syntax commands which creates dynamically mapname_path method.
  10. sinatra_more Library with agnostic generators, form builders, named route mappings, easy mailer support among other functionality.
  11. sinatra-authorization HTTP auth helpers

Extensions which provide class methods

  1. snap provides support for named routes and helper methods for building URLs for use in links and redirects.

Extensions which handle setup and configuration

  1. sinatra-mongoid sets up a MongoDB connection, provides Mongoid to your app, and provides options for configuration.

Add more! Examples described in Writing Extensions.