File: README.md

package info (click to toggle)
ruby-sinatra-contrib 1.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 572 kB
  • ctags: 392
  • sloc: ruby: 4,722; makefile: 2
file content (144 lines) | stat: -rw-r--r-- 3,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
[![Build Status](https://secure.travis-ci.org/sinatra/sinatra-contrib.png)](http://travis-ci.org/sinatra/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,
  Erubis 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.

## Custom Extensions

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

Currently included:

* `sinatra/decompile`: Recreates path patterns from Sinatra's internal data
  structures (used by other extensions).

* `sinatra/reloader`: Automatically reloads Ruby files on code changes.

## 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

# 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.


# Usage

## Classic Style

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

``` ruby
require 'sinatra'
require 'sinatra/content_for'
```

Common extensions:

``` ruby
require 'sinatra'
require 'sinatra/contrib'
```

All extensions:

``` ruby
require 'sinatra'
require 'sinatra/contrib/all'
```

## Modular Style

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

``` ruby
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:

``` ruby
require 'sinatra/base'
require 'sinatra/contrib'

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

All extensions:

``` ruby
require 'sinatra/base'
require 'sinatra/contrib/all'

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

## Documentation

For more info check the [official docs](http://www.sinatrarb.com/contrib/) and
[api docs](http://rubydoc.info/gems/sinatra-contrib/1.4.0/frames).