Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (55 sloc) 2.76 KB
title layout
Sinatra: Extensions in the Wild
default

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 github.com, type and run the following command:

gem install sbfaulkner-sinatra-prawn -s http://gems.github.com

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-content-for provides content_for helper similar to Rails one.
  6. sinatra-url-for construct absolute paths and full URLs to actions in a Sinatra application
  7. 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.
  8. sinatra-mapping implements map in the DSL syntax commands which creates dynamically mapname_path method.

Extensions which provide class methods

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

Add more! Examples described in Writing Extensions.

Something went wrong with that request. Please try again.