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 github.com, type and run the following command:
gem install sbfaulkner-sinatra-prawn -s http://gems.github.com
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
- sinatra-prawn adds support for pdf rendering with Prawn templates.
- sinatra-markaby enables rendering of html files using markaby templates.
- sinatra-maruku provides Maruku templates for a Sinatra application.
- sinatra-rdiscount provides RDiscount templates for a Sinatra application.
content_forhelper similar to Rails one.
- sinatra-url-for construct absolute paths and full URLs to actions in a Sinatra application
link_taghelpers. These helpers construct correct absolute paths for applications dispatched to sub URI.
Extensions which provide class methods
There are none available at the moment, except examples described in Writing Extensions.