Sinatra: Using Extensions
Extensions provide helper or class methods for Sinatra applications. These methods are customarily listed and described on extensions home pages, many of which are listed below.
Using an extension is usually as simple as installing a gem or library and requiring a file. Consult these steps if you run into problems:
Install the gem or vendor the library with your project:
gem install sinatra-prawn
Require the extension in your application:
If your application is "classic" (i.e., you
require 'sinatra'and define the application in the main/top-level context), you're done. The extension methods should be available to your application.
If your application subclasses
Sinatra::Base, you have to register the extension in your subclass:
These extensions add helper methods to the request context:
- 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.
- sinatra-effigy provides Effigy templates and views 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.
mapin the DSL syntax commands which creates dynamically
- sinatra_more Library with agnostic generators, form builders, named route mappings, easy mailer support among other functionality.
- sinatra-authorization HTTP auth helpers
- sinatra-simple-navigation enables creating navigations using the simple-navigation gem.
These extensions add methods to Sinatra's application DSL:
- snap provides support for named routes and helper methods for building URLs for use in links and redirects.
Extensions which handle setup and configuration
- sinatra-mongoid sets up a MongoDB connection, provides Mongoid to your app, and provides options for configuration.
Add more! See Writing Extensions for more information about creating your own.