2016-07-20 01:11:08 -04:00
|
|
|
# Sinatra::Contrib
|
|
|
|
|
2011-03-29 04:05:12 -04:00
|
|
|
Collection of common Sinatra extensions, semi-officially supported.
|
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
## Goals
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
* For every future Sinatra release, have at least one fully compatible release
|
|
|
|
* High code quality, high test coverage
|
|
|
|
* Include plugins people usually ask for a lot
|
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
## Included extensions
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
### Common Extensions
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
These are common extension which will not add significant overhead or change any
|
|
|
|
behavior of already existing APIs. They do not add any dependencies not already
|
|
|
|
installed with this gem.
|
|
|
|
|
|
|
|
Currently included:
|
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/capture`][sinatra-capture]: Let's you capture the content of blocks in templates.
|
2011-05-09 02:36:48 -04:00
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/config_file`][sinatra-config-file]: Allows loading configuration from yaml files.
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/content_for`][sinatra-content-for]: Adds Rails-style `content_for` helpers to Haml, Erb,
|
2011-03-29 04:05:12 -04:00
|
|
|
Erubis and Slim.
|
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/cookies`][sinatra-cookies]: A `cookies` helper for reading and writing cookies.
|
2011-09-04 21:13:40 -04:00
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/engine_tracking`][sinatra-engine-tracking]: Adds methods like `haml?` that allow helper
|
2011-05-09 02:36:48 -04:00
|
|
|
methods to check whether they are called from within a template.
|
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/json`][sinatra-json]: Adds a `#json` helper method to return JSON documents.
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/link_header`][sinatra-link-header]: Helpers for generating `link` HTML tags and
|
2011-03-29 04:05:12 -04:00
|
|
|
corresponding `Link` HTTP headers. Adds `link`, `stylesheet` and `prefetch`
|
|
|
|
helper methods.
|
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/multi_route`][sinatra-multi-route]: Adds ability to define one route block for multiple
|
2011-09-04 21:13:27 -04:00
|
|
|
routes and multiple or custom HTTP verbs.
|
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/namespace`][sinatra-namespace]: Adds namespace support to Sinatra.
|
2011-05-09 02:36:48 -04:00
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/respond_with`][sinatra-respond-with]: Choose action and/or template automatically
|
2011-03-29 04:05:12 -04:00
|
|
|
depending on the incoming request. Adds helpers `respond_to` and
|
|
|
|
`respond_with`.
|
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/custom_logger`][sinatra-custom-logger]: This extension allows you to define your own
|
2014-03-19 03:14:01 -04:00
|
|
|
logger instance using +logger+ setting. That logger then will
|
|
|
|
be available as #logger helper method in your routes and views.
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/required_params`][sinatra-required-params]: Ensure if required query parameters exist
|
2014-04-19 12:28:49 -04:00
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
### Custom Extensions
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
These extensions may add additional dependencies and enhance the behavior of the
|
2011-03-30 14:49:11 -04:00
|
|
|
existing APIs.
|
|
|
|
|
|
|
|
Currently included:
|
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/reloader`][sinatra-reloader]: Automatically reloads Ruby files on code changes.
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
### Other Tools
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/extension`][sinatra-extension]: Mixin for writing your own Sinatra extensions.
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2017-05-15 20:20:50 -04:00
|
|
|
* [`sinatra/test_helpers`][sinatra-test-helpers]: Helper methods to ease testing your Sinatra
|
2011-03-29 04:05:12 -04:00
|
|
|
application. Partly extracted from Sinatra. Testing framework agnostic
|
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
## Installation
|
|
|
|
|
2016-05-23 09:13:57 -04:00
|
|
|
Add `gem 'sinatra-contrib'` to *Gemfile*, then execute `bundle install`.
|
2012-09-21 17:59:35 -04:00
|
|
|
|
|
|
|
If you don't use Bundler, install the gem manually by executing `gem install sinatra-contrib` in your command line.
|
|
|
|
|
2016-07-23 00:41:57 -04:00
|
|
|
### Git
|
|
|
|
|
|
|
|
If you want to use the gem from git, for whatever reason, you can do the following:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
github 'sinatra/sinatra' do
|
|
|
|
gem 'sinatra-contrib'
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
Within this block you can also specify other gems from this git repository.
|
2012-09-21 17:59:35 -04:00
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
## Usage
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
### Classic Style
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
A single extension (example: sinatra-content-for):
|
|
|
|
|
2011-05-24 13:50:01 -04:00
|
|
|
``` ruby
|
|
|
|
require 'sinatra'
|
|
|
|
require 'sinatra/content_for'
|
|
|
|
```
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
Common extensions:
|
|
|
|
|
2011-05-24 13:50:01 -04:00
|
|
|
``` ruby
|
|
|
|
require 'sinatra'
|
|
|
|
require 'sinatra/contrib'
|
|
|
|
```
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
All extensions:
|
|
|
|
|
2011-05-24 13:50:01 -04:00
|
|
|
``` ruby
|
|
|
|
require 'sinatra'
|
|
|
|
require 'sinatra/contrib/all'
|
|
|
|
```
|
2011-03-29 04:05:12 -04:00
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
### Modular Style
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
A single extension (example: sinatra-content-for):
|
|
|
|
|
2011-05-24 13:50:01 -04:00
|
|
|
``` ruby
|
|
|
|
require 'sinatra/base'
|
|
|
|
require 'sinatra/content_for'
|
2011-09-02 17:01:03 -04:00
|
|
|
require 'sinatra/namespace'
|
2011-05-24 13:50:01 -04:00
|
|
|
|
|
|
|
class MyApp < Sinatra::Base
|
|
|
|
# Note: Some modules are extensions, some helpers, see the specific
|
|
|
|
# documentation or the source
|
|
|
|
helpers Sinatra::ContentFor
|
2011-09-02 17:01:03 -04:00
|
|
|
register Sinatra::Namespace
|
2011-05-24 13:50:01 -04:00
|
|
|
end
|
|
|
|
```
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
Common extensions:
|
|
|
|
|
2011-05-24 13:50:01 -04:00
|
|
|
``` ruby
|
|
|
|
require 'sinatra/base'
|
|
|
|
require 'sinatra/contrib'
|
|
|
|
|
|
|
|
class MyApp < Sinatra::Base
|
|
|
|
register Sinatra::Contrib
|
|
|
|
end
|
|
|
|
```
|
2011-03-29 04:05:12 -04:00
|
|
|
|
|
|
|
All extensions:
|
|
|
|
|
2011-05-24 13:50:01 -04:00
|
|
|
``` ruby
|
|
|
|
require 'sinatra/base'
|
2012-02-01 14:02:02 -05:00
|
|
|
require 'sinatra/contrib/all'
|
2011-05-24 13:50:01 -04:00
|
|
|
|
|
|
|
class MyApp < Sinatra::Base
|
|
|
|
register Sinatra::Contrib
|
|
|
|
end
|
|
|
|
```
|
2013-08-10 23:14:28 -04:00
|
|
|
|
2016-07-20 01:11:08 -04:00
|
|
|
### Documentation
|
2013-08-10 23:14:28 -04:00
|
|
|
|
|
|
|
For more info check the [official docs](http://www.sinatrarb.com/contrib/) and
|
2016-04-21 07:02:31 -04:00
|
|
|
[api docs](http://www.rubydoc.info/gems/sinatra-contrib).
|
2017-05-15 20:20:50 -04:00
|
|
|
|
2017-06-08 05:33:08 -04:00
|
|
|
[sinatra-reloader]: http://www.sinatrarb.com/contrib/reloader
|
|
|
|
[sinatra-namespace]: http://www.sinatrarb.com/contrib/namespace
|
|
|
|
[sinatra-content-for]: http://www.sinatrarb.com/contrib/content_for
|
|
|
|
[sinatra-cookies]: http://www.sinatrarb.com/contrib/cookies
|
|
|
|
[sinatra-streaming]: http://www.sinatrarb.com/contrib/streaming
|
|
|
|
[sinatra-webdav]: http://www.sinatrarb.com/contrib/webdav
|
|
|
|
[sinatra-runner]: http://www.sinatrarb.com/contrib/runner
|
|
|
|
[sinatra-extension]: http://www.sinatrarb.com/contrib/extension
|
2017-09-09 03:15:17 -04:00
|
|
|
[sinatra-test-helpers]: https://github.com/sinatra/sinatra/blob/master/sinatra-contrib/lib/sinatra/test_helpers.rb
|
2017-06-08 05:33:08 -04:00
|
|
|
[sinatra-required-params]: http://www.sinatrarb.com/contrib/required_params
|
|
|
|
[sinatra-custom-logger]: http://www.sinatrarb.com/contrib/custom_logger
|
|
|
|
[sinatra-multi-route]: http://www.sinatrarb.com/contrib/multi_route
|
|
|
|
[sinatra-json]: http://www.sinatrarb.com/contrib/json
|
|
|
|
[sinatra-respond-with]: http://www.sinatrarb.com/contrib/respond_with
|
|
|
|
[sinatra-config-file]: http://www.sinatrarb.com/contrib/config_file
|
|
|
|
[sinatra-link-header]: http://www.sinatrarb.com/contrib/link_header
|
|
|
|
[sinatra-capture]: http://www.sinatrarb.com/contrib/capture
|
2017-09-09 03:15:17 -04:00
|
|
|
[sinatra-engine-tracking]: https://github.com/sinatra/sinatra/blob/master/sinatra-contrib/lib/sinatra/engine_tracking.rb
|
2017-05-15 20:20:50 -04:00
|
|
|
|