1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/sinatra-contrib
Patrik Ragnarsson f9fa73da34 Revert "Allow running with Rack 3. (#1811)"
This reverts commit 2ccd0dc29d.

It doesn't make sense to have this in master when it is not working. CI
will install Rack 3 and fail jobs. We don't know if we break something
for Rack 2 now.
2022-12-28 21:21:08 +01:00
..
lib/sinatra 3.0.5 release 2022-12-16 18:13:16 -05:00
spec Support Haml 6 2022-09-27 10:22:16 -04:00
.gitignore ignore Gemfile.lock 2013-08-19 18:44:27 -04:00
.rspec Use same rake task and config for tests in sinatra-contrib and rack-protection 2022-02-05 13:10:04 +01:00
Gemfile Revert "Allow running with Rack 3. (#1811)" 2022-12-28 21:21:08 +01:00
ideas.md Delete sass 2022-03-11 20:50:14 +01:00
LICENSE Update LICENSE(s) 2017-03-19 12:05:31 +09:00
Rakefile Setup Rubocop (#1537) 2022-07-31 08:56:44 -04:00
README.md Deprecate Sinatra Reloader 2022-08-02 15:45:05 -04:00
sinatra-contrib.gemspec Support Haml 6 2022-09-27 10:22:16 -04:00

Sinatra::Contrib

Collection of common Sinatra extensions, semi-officially supported.

Goals

  • 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

Included extensions

Common Extensions

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:

  • sinatra/capture: Let's you capture the content of blocks in templates.

  • sinatra/config_file: Allows loading configuration from yaml files.

  • sinatra/content_for: Adds Rails-style content_for helpers to Haml, Erb, Erubi and Slim.

  • sinatra/cookies: A cookies helper for reading and writing cookies.

  • sinatra/engine_tracking: Adds methods like haml? that allow helper methods to check whether they are called from within a template.

  • sinatra/json: Adds a #json helper method to return JSON documents.

  • sinatra/link_header: Helpers for generating link HTML tags and corresponding Link HTTP headers. Adds link, stylesheet and prefetch helper methods.

  • sinatra/multi_route: Adds ability to define one route block for multiple routes and multiple or custom HTTP verbs.

  • sinatra/namespace: Adds namespace support to Sinatra.

  • sinatra/respond_with: Choose action and/or template automatically depending on the incoming request. Adds helpers respond_to and respond_with.

  • sinatra/custom_logger: This extension allows you to define your own logger instance using +logger+ setting. That logger then will be available as #logger helper method in your routes and views.

  • sinatra/required_params: Ensure if required query parameters exist

Custom Extensions

These extensions may add additional dependencies and enhance the behavior of the existing APIs.

Currently included:

Other Tools

  • sinatra/extension: Mixin for writing your own Sinatra extensions.

  • sinatra/test_helpers: Helper methods to ease testing your Sinatra application. Partly extracted from Sinatra. Testing framework agnostic

  • sinatra/quiet_logger: Extension to exclude specific pathes from access log. It works by patching Rack::CommonLogger

Installation

Add gem 'sinatra-contrib' to Gemfile, then execute bundle install.

If you don't use Bundler, install the gem manually by executing gem install sinatra-contrib in your command line.

Git

If you want to use the gem from git, for whatever reason, you can do the following:

github 'sinatra/sinatra' do
  gem 'sinatra-contrib'
end

Within this block you can also specify other gems from this git repository.

Usage

Classic Style

A single extension (example: sinatra-content-for):

require 'sinatra'
require 'sinatra/content_for'

Common extensions:

require 'sinatra'
require 'sinatra/contrib'

All extensions:

require 'sinatra'
require 'sinatra/contrib/all'

Modular Style

A single extension (example: sinatra-content-for):

require 'sinatra/base'
require 'sinatra/content_for'
require 'sinatra/namespace'

class MyApp < Sinatra::Base
  # Note: Some modules are extensions, some helpers, see the specific
  # documentation or the source
  helpers Sinatra::ContentFor
  register Sinatra::Namespace
end

Common extensions:

require 'sinatra/base'
require 'sinatra/contrib'

class MyApp < Sinatra::Base
  register Sinatra::Contrib
end

All extensions:

require 'sinatra/base'
require 'sinatra/contrib/all'

class MyApp < Sinatra::Base
  register Sinatra::Contrib
end

Documentation

For more info check the official docs and api docs.