sinatra 1.4.8 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +77 -47
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +37 -49
- data/MAINTENANCE.md +42 -0
- data/README.de.md +5 -5
- data/README.es.md +5 -5
- data/README.fr.md +9 -9
- data/README.hu.md +3 -3
- data/README.ja.md +19 -8
- data/README.ko.md +8 -8
- data/README.md +90 -61
- data/README.pt-br.md +3 -3
- data/README.pt-pt.md +2 -2
- data/README.ru.md +42 -26
- data/README.zh.md +8 -8
- data/Rakefile +0 -6
- data/SECURITY.md +35 -0
- data/lib/sinatra/base.rb +113 -161
- data/lib/sinatra/main.rb +1 -0
- data/lib/sinatra/show_exceptions.rb +8 -8
- data/lib/sinatra/version.rb +1 -1
- data/sinatra.gemspec +7 -4
- metadata +34 -168
- data/lib/sinatra/ext.rb +0 -17
- data/test/asciidoctor_test.rb +0 -72
- data/test/base_test.rb +0 -167
- data/test/builder_test.rb +0 -91
- data/test/coffee_test.rb +0 -96
- data/test/compile_test.rb +0 -183
- data/test/contest.rb +0 -91
- data/test/creole_test.rb +0 -65
- data/test/delegator_test.rb +0 -160
- data/test/encoding_test.rb +0 -20
- data/test/erb_test.rb +0 -116
- data/test/extensions_test.rb +0 -98
- data/test/filter_test.rb +0 -487
- data/test/haml_test.rb +0 -109
- data/test/helper.rb +0 -132
- data/test/helpers_test.rb +0 -1917
- data/test/integration/app.rb +0 -79
- data/test/integration_helper.rb +0 -236
- data/test/integration_test.rb +0 -104
- data/test/less_test.rb +0 -69
- data/test/liquid_test.rb +0 -77
- data/test/mapped_error_test.rb +0 -285
- data/test/markaby_test.rb +0 -80
- data/test/markdown_test.rb +0 -85
- data/test/mediawiki_test.rb +0 -68
- data/test/middleware_test.rb +0 -68
- data/test/nokogiri_test.rb +0 -67
- data/test/public/favicon.ico +0 -0
- data/test/public/hello+world.txt +0 -1
- data/test/rabl_test.rb +0 -89
- data/test/rack_test.rb +0 -45
- data/test/radius_test.rb +0 -59
- data/test/rdoc_test.rb +0 -66
- data/test/readme_test.rb +0 -130
- data/test/request_test.rb +0 -100
- data/test/response_test.rb +0 -63
- data/test/result_test.rb +0 -76
- data/test/route_added_hook_test.rb +0 -59
- data/test/routing_test.rb +0 -1456
- data/test/sass_test.rb +0 -115
- data/test/scss_test.rb +0 -88
- data/test/server_test.rb +0 -56
- data/test/settings_test.rb +0 -582
- data/test/sinatra_test.rb +0 -12
- data/test/slim_test.rb +0 -102
- data/test/static_test.rb +0 -266
- data/test/streaming_test.rb +0 -149
- data/test/stylus_test.rb +0 -90
- data/test/templates_test.rb +0 -382
- data/test/textile_test.rb +0 -65
- data/test/views/a/in_a.str +0 -1
- data/test/views/ascii.erb +0 -2
- data/test/views/b/in_b.str +0 -1
- data/test/views/calc.html.erb +0 -1
- data/test/views/error.builder +0 -3
- data/test/views/error.erb +0 -3
- data/test/views/error.haml +0 -3
- data/test/views/error.sass +0 -2
- data/test/views/explicitly_nested.str +0 -1
- data/test/views/foo/hello.test +0 -1
- data/test/views/hello.asciidoc +0 -1
- data/test/views/hello.builder +0 -1
- data/test/views/hello.coffee +0 -1
- data/test/views/hello.creole +0 -1
- data/test/views/hello.erb +0 -1
- data/test/views/hello.haml +0 -1
- data/test/views/hello.less +0 -5
- data/test/views/hello.liquid +0 -1
- data/test/views/hello.mab +0 -1
- data/test/views/hello.md +0 -1
- data/test/views/hello.mediawiki +0 -1
- data/test/views/hello.nokogiri +0 -1
- data/test/views/hello.rabl +0 -2
- data/test/views/hello.radius +0 -1
- data/test/views/hello.rdoc +0 -1
- data/test/views/hello.sass +0 -2
- data/test/views/hello.scss +0 -3
- data/test/views/hello.slim +0 -1
- data/test/views/hello.str +0 -1
- data/test/views/hello.styl +0 -2
- data/test/views/hello.test +0 -1
- data/test/views/hello.textile +0 -1
- data/test/views/hello.wlang +0 -1
- data/test/views/hello.yajl +0 -1
- data/test/views/layout2.builder +0 -3
- data/test/views/layout2.erb +0 -2
- data/test/views/layout2.haml +0 -2
- data/test/views/layout2.liquid +0 -2
- data/test/views/layout2.mab +0 -2
- data/test/views/layout2.nokogiri +0 -3
- data/test/views/layout2.rabl +0 -3
- data/test/views/layout2.radius +0 -2
- data/test/views/layout2.slim +0 -3
- data/test/views/layout2.str +0 -2
- data/test/views/layout2.test +0 -1
- data/test/views/layout2.wlang +0 -2
- data/test/views/nested.str +0 -1
- data/test/views/utf8.erb +0 -2
- data/test/wlang_test.rb +0 -87
- data/test/yajl_test.rb +0 -86
data/MAINTENANCE.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Sinatra maintenance
|
2
|
+
|
3
|
+
## Versions
|
4
|
+
|
5
|
+
### Unstable release
|
6
|
+
|
7
|
+
The next major version of Sinatra will be released from the master branch.
|
8
|
+
|
9
|
+
* Current proposed major release: 2.0.0
|
10
|
+
|
11
|
+
### Stable release
|
12
|
+
|
13
|
+
The current stable version of Sinatra is 1.4 series, and released from the stable branch.
|
14
|
+
|
15
|
+
## Issues
|
16
|
+
|
17
|
+
### New features
|
18
|
+
|
19
|
+
New features will only be added to the master branch and will not be made available in point releases.
|
20
|
+
|
21
|
+
### Bug fixes
|
22
|
+
|
23
|
+
Only the latest release series will receive bug fixes. When enough bugs are fixed and its deemed worthy to release a new gem, this is the branch it happens from.
|
24
|
+
|
25
|
+
* Current release series: 1.4.x
|
26
|
+
|
27
|
+
### Security issues
|
28
|
+
|
29
|
+
The current release series will receive patches and new versions in case of a security issue.
|
30
|
+
|
31
|
+
* Current release series: 1.4.x
|
32
|
+
|
33
|
+
### Severe security issues
|
34
|
+
|
35
|
+
For severe security issues we will provide new versions as above, and also the last major release series will receive patches and new versions. The classification of the security issue is judged by the core team.
|
36
|
+
|
37
|
+
* Current release series: 1.4.x
|
38
|
+
* Next most recent release series: 1.3.x
|
39
|
+
|
40
|
+
### Unsupported Release Series
|
41
|
+
|
42
|
+
When a release series is no longer supported, it’s your own responsibility to deal with bugs and security issues. We may provide back-ports of the fixes and publish them to git, however there will be no new versions released. If you are not comfortable maintaining your own versions, you should upgrade to a supported version.
|
data/README.de.md
CHANGED
@@ -204,7 +204,7 @@ end
|
|
204
204
|
Routen mit regulären Ausdrücken sind auch möglich:
|
205
205
|
|
206
206
|
```ruby
|
207
|
-
get
|
207
|
+
get /\/hallo\/([\w]+)/ do
|
208
208
|
"Hallo, #{params['captures'].first}!"
|
209
209
|
end
|
210
210
|
```
|
@@ -389,7 +389,7 @@ end
|
|
389
389
|
Oder unter Verwendung eines negativen look ahead:
|
390
390
|
|
391
391
|
```ruby
|
392
|
-
get %r{
|
392
|
+
get %r{(?!/index)} do
|
393
393
|
# ...
|
394
394
|
end
|
395
395
|
```
|
@@ -2039,7 +2039,7 @@ configure do
|
|
2039
2039
|
end
|
2040
2040
|
```
|
2041
2041
|
|
2042
|
-
Läuft nur, wenn die Umgebung (
|
2042
|
+
Läuft nur, wenn die Umgebung (APP_ENV-Umgebungsvariable) auf `:production`
|
2043
2043
|
gesetzt ist:
|
2044
2044
|
|
2045
2045
|
```ruby
|
@@ -2239,7 +2239,7 @@ set :protection, :except => [:path_traversal, :session_hijacking]
|
|
2239
2239
|
## Umgebungen
|
2240
2240
|
|
2241
2241
|
Es gibt drei voreingestellte Umgebungen in Sinatra: `"development"`,
|
2242
|
-
`"production"` und `"test"`. Umgebungen können über die `
|
2242
|
+
`"production"` und `"test"`. Umgebungen können über die `APP_ENV`
|
2243
2243
|
Umgebungsvariable gesetzt werden. Die Standardeinstellung ist `"development"`.
|
2244
2244
|
In diesem Modus werden alle Templates zwischen Requests neu geladen. Dazu gibt
|
2245
2245
|
es besondere Fehlerseiten für 404 Stati und Fehlermeldungen. In `"production"`
|
@@ -2408,7 +2408,7 @@ class MyAppTest < Minitest::Test
|
|
2408
2408
|
assert_equal 'Hallo Frank!', last_response.body
|
2409
2409
|
end
|
2410
2410
|
|
2411
|
-
def
|
2411
|
+
def test_with_user_agent
|
2412
2412
|
get '/', {}, 'HTTP_USER_AGENT' => 'Songbird'
|
2413
2413
|
assert_equal "Du verwendest Songbird!", last_response.body
|
2414
2414
|
end
|
data/README.es.md
CHANGED
@@ -117,7 +117,7 @@ end
|
|
117
117
|
Rutas con Expresiones Regulares:
|
118
118
|
|
119
119
|
```ruby
|
120
|
-
get
|
120
|
+
get /\/hola\/([\w]+)/ do
|
121
121
|
"Hola, #{params['captures'].first}!"
|
122
122
|
end
|
123
123
|
```
|
@@ -282,7 +282,7 @@ end
|
|
282
282
|
O, usando un lookahead negativo:
|
283
283
|
|
284
284
|
```ruby
|
285
|
-
get %r{
|
285
|
+
get %r{(?!/index)} do
|
286
286
|
# ...
|
287
287
|
end
|
288
288
|
```
|
@@ -1808,7 +1808,7 @@ configure do
|
|
1808
1808
|
end
|
1809
1809
|
```
|
1810
1810
|
|
1811
|
-
Ejecutar únicamente cuando el entorno (la variable de entorno
|
1811
|
+
Ejecutar únicamente cuando el entorno (la variable de entorno APP_ENV) es
|
1812
1812
|
`:production`:
|
1813
1813
|
|
1814
1814
|
```ruby
|
@@ -1918,7 +1918,7 @@ set :protection, :except => [:path_traversal, :session_hijacking]
|
|
1918
1918
|
<dt>environment</dt>
|
1919
1919
|
<dd>
|
1920
1920
|
Entorno actual, por defecto toma el valor de
|
1921
|
-
<tt>ENV['
|
1921
|
+
<tt>ENV['APP_ENV']</tt>, o <tt>"development"</tt> si no
|
1922
1922
|
está disponible.
|
1923
1923
|
</dd>
|
1924
1924
|
|
@@ -2080,7 +2080,7 @@ de `production` y `test`, donde se cachean.
|
|
2080
2080
|
especiales que muestran un stack trace en el navegador cuando son disparados.
|
2081
2081
|
|
2082
2082
|
Para utilizar alguno de los otros entornos puede asignarse el valor
|
2083
|
-
correspondiente a la variable de entorno `
|
2083
|
+
correspondiente a la variable de entorno `APP_ENV`, o bien utilizar la opción
|
2084
2084
|
`-e` al ejecutar la aplicación:
|
2085
2085
|
|
2086
2086
|
```shell
|
data/README.fr.md
CHANGED
@@ -209,7 +209,7 @@ end
|
|
209
209
|
Une route peut aussi être définie par une expression régulière :
|
210
210
|
|
211
211
|
```ruby
|
212
|
-
get
|
212
|
+
get /\/bonjour\/([\w]+)/ do
|
213
213
|
"Bonjour, #{params['captures'].first} !"
|
214
214
|
end
|
215
215
|
```
|
@@ -390,7 +390,7 @@ end
|
|
390
390
|
Ou bien en utilisant cette expression regulière :
|
391
391
|
|
392
392
|
```ruby
|
393
|
-
get %r{
|
393
|
+
get %r{(?!/index)} do
|
394
394
|
# ...
|
395
395
|
end
|
396
396
|
```
|
@@ -2016,7 +2016,7 @@ configure do
|
|
2016
2016
|
end
|
2017
2017
|
```
|
2018
2018
|
|
2019
|
-
Lancé si l'environnement (variable d'environnement
|
2019
|
+
Lancé si l'environnement (variable d'environnement APP_ENV) est `:production` :
|
2020
2020
|
|
2021
2021
|
```ruby
|
2022
2022
|
configure :production do
|
@@ -2121,7 +2121,7 @@ set :protection, :session => true
|
|
2121
2121
|
</dd>
|
2122
2122
|
|
2123
2123
|
<dt>environment</dt>
|
2124
|
-
<dd>environnement courant, par défaut <tt>ENV['
|
2124
|
+
<dd>environnement courant, par défaut <tt>ENV['APP_ENV']</tt>, ou
|
2125
2125
|
<tt>"development"</tt> si absent.</dd>
|
2126
2126
|
|
2127
2127
|
<dt>logging</dt>
|
@@ -2229,7 +2229,7 @@ set :protection, :session => true
|
|
2229
2229
|
|
2230
2230
|
Il existe trois environnements prédéfinis : `"development"`,
|
2231
2231
|
`"production"` et `"test"`. Les environements peuvent être
|
2232
|
-
sélectionné via la variable d'environnement `
|
2232
|
+
sélectionné via la variable d'environnement `APP_ENV`. Sa valeur par défaut
|
2233
2233
|
est `"development"`. Dans ce mode, tous les templates sont rechargés à
|
2234
2234
|
chaque requête. Des handlers spécifiques pour `not_found` et
|
2235
2235
|
`error` sont installés pour vous permettre d'avoir une pile de trace
|
@@ -2237,10 +2237,10 @@ dans votre navigateur. En mode `"production"` et `"test"` les
|
|
2237
2237
|
templates sont mis en cache par défaut.
|
2238
2238
|
|
2239
2239
|
Pour exécuter votre application dans un environnement différent, définissez la
|
2240
|
-
variable d'environnement `
|
2240
|
+
variable d'environnement `APP_ENV` :
|
2241
2241
|
|
2242
|
-
```shell
|
2243
|
-
|
2242
|
+
``` shell
|
2243
|
+
APP_ENV=production ruby my_app.rb
|
2244
2244
|
```
|
2245
2245
|
|
2246
2246
|
Vous pouvez utiliser une des méthodes `development?`, `test?` et `production?`
|
@@ -2405,7 +2405,7 @@ class MonTest < Minitest::Test
|
|
2405
2405
|
assert_equal 'Salut Frank !', last_response.body
|
2406
2406
|
end
|
2407
2407
|
|
2408
|
-
def
|
2408
|
+
def test_avec_agent
|
2409
2409
|
get '/', {}, 'HTTP_USER_AGENT' => 'Songbird'
|
2410
2410
|
assert_equal "Vous utilisez Songbird !", last_response.body
|
2411
2411
|
end
|
data/README.hu.md
CHANGED
@@ -88,7 +88,7 @@ Az útvonalmintákban szerepelhetnek joker paraméterek is, melyeket a
|
|
88
88
|
Reguláris kifejezéseket is felvehetünk az útvonalba:
|
89
89
|
|
90
90
|
```ruby
|
91
|
-
get
|
91
|
+
get /\/hello\/([\w]+)/ do
|
92
92
|
"Helló, #{params['captures'].first}!"
|
93
93
|
end
|
94
94
|
```
|
@@ -411,7 +411,7 @@ Csak indításkor, de minden környezetre érvényesen fusson le:
|
|
411
411
|
end
|
412
412
|
```
|
413
413
|
|
414
|
-
Csak akkor fusson le, ha a környezet (a
|
414
|
+
Csak akkor fusson le, ha a környezet (a APP_ENV környezeti változóban)
|
415
415
|
`:production`-ra van állítva:
|
416
416
|
|
417
417
|
```ruby
|
@@ -562,7 +562,7 @@ könyvtárat ajánljuk:
|
|
562
562
|
assert_equal 'Helló Frici!', last_response.body
|
563
563
|
end
|
564
564
|
|
565
|
-
def
|
565
|
+
def test_with_user_agent
|
566
566
|
get '/', {}, 'HTTP_USER_AGENT' => 'Songbird'
|
567
567
|
assert_equal "Songbird-öt használsz!", last_response.body
|
568
568
|
end
|
data/README.ja.md
CHANGED
@@ -160,6 +160,15 @@ end
|
|
160
160
|
ルーティングは定義された順番にマッチします。
|
161
161
|
リクエストに最初にマッチしたルーティングが呼び出されます。
|
162
162
|
|
163
|
+
トレイリングスラッシュを付けたルートは、そうでないルートと異なったものになります。
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
get '/foo' do
|
167
|
+
# Does not match "GET /foo/"
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
|
163
172
|
ルーティングのパターンは名前付きパラメータを含むことができ、
|
164
173
|
`params`ハッシュで取得できます。
|
165
174
|
|
@@ -208,7 +217,7 @@ end
|
|
208
217
|
ルーティングを正規表現にマッチさせることもできます。
|
209
218
|
|
210
219
|
```ruby
|
211
|
-
get
|
220
|
+
get /\/hello\/([\w]+)/ do
|
212
221
|
"Hello, #{params['captures'].first}!"
|
213
222
|
end
|
214
223
|
```
|
@@ -365,7 +374,7 @@ end
|
|
365
374
|
または、否定先読みを使って:
|
366
375
|
|
367
376
|
```ruby
|
368
|
-
get %r{
|
377
|
+
get %r{(?!/index)} do
|
369
378
|
# ...
|
370
379
|
end
|
371
380
|
```
|
@@ -1461,6 +1470,8 @@ post '/message' do
|
|
1461
1470
|
end
|
1462
1471
|
```
|
1463
1472
|
|
1473
|
+
クライアントはソケットに書き込もうとしている接続を閉じることも可能です。そのため、記述しようとする前に`out.closed?`をチェックすることを勧めます。
|
1474
|
+
|
1464
1475
|
### ロギング(Logging)
|
1465
1476
|
|
1466
1477
|
リクエストスコープにおいて、`logger`ヘルパーは`Logger`インスタンスを作り出します。
|
@@ -1868,7 +1879,7 @@ configure do
|
|
1868
1879
|
end
|
1869
1880
|
```
|
1870
1881
|
|
1871
|
-
環境設定(`
|
1882
|
+
環境設定(`APP_ENV`環境変数)が`:production`に設定されている時だけ実行する方法:
|
1872
1883
|
|
1873
1884
|
```ruby
|
1874
1885
|
configure :production do
|
@@ -1958,7 +1969,7 @@ set :protection, :session => true
|
|
1958
1969
|
|
1959
1970
|
<dt>environment</dt>
|
1960
1971
|
<dd>
|
1961
|
-
現在の環境。デフォルトは<tt>ENV['
|
1972
|
+
現在の環境。デフォルトは<tt>ENV['APP_ENV']</tt>、それが無い場合は<tt>"development"</tt>。
|
1962
1973
|
</dd>
|
1963
1974
|
|
1964
1975
|
<dt>logging</dt>
|
@@ -2070,12 +2081,12 @@ set :protection, :session => true
|
|
2070
2081
|
|
2071
2082
|
## 環境設定(Environments)
|
2072
2083
|
|
2073
|
-
3種類の既定環境、`"development"`、`"production"`および`"test"`があります。環境は、`
|
2084
|
+
3種類の既定環境、`"development"`、`"production"`および`"test"`があります。環境は、`APP_ENV`環境変数を通して設定できます。デフォルト値は、`"development"`です。`"development"`環境において、すべてのテンプレートは、各リクエスト間で再ロードされ、そして、特別の`not_found`および`error`ハンドラがブラウザにスタックトレースを表示します。`"production"`および`"test"`環境においては、テンプレートはデフォルトでキャッシュされます。
|
2074
2085
|
|
2075
|
-
異なる環境を走らせるには、`
|
2086
|
+
異なる環境を走らせるには、`APP_ENV`環境変数を設定します。
|
2076
2087
|
|
2077
2088
|
```shell
|
2078
|
-
|
2089
|
+
APP_ENV=production ruby my_app.rb
|
2079
2090
|
```
|
2080
2091
|
|
2081
2092
|
既定メソッド、`development?`、`test?`および`production?`を、現在の環境設定を確認するために使えます。
|
@@ -2219,7 +2230,7 @@ class MyAppTest < Minitest::Test
|
|
2219
2230
|
assert_equal 'Hello Frank!', last_response.body
|
2220
2231
|
end
|
2221
2232
|
|
2222
|
-
def
|
2233
|
+
def test_with_user_agent
|
2223
2234
|
get '/', {}, 'HTTP_USER_AGENT' => 'Songbird'
|
2224
2235
|
assert_equal "Songbirdを使ってます!", last_response.body
|
2225
2236
|
end
|
data/README.ko.md
CHANGED
@@ -207,7 +207,7 @@ end
|
|
207
207
|
라우터는 정규표현식으로 매치할 수 있습니다.
|
208
208
|
|
209
209
|
```ruby
|
210
|
-
get
|
210
|
+
get /\/hello\/([\w]+)/ do
|
211
211
|
"Hello, #{params['captures'].first}!"
|
212
212
|
end
|
213
213
|
```
|
@@ -374,7 +374,7 @@ end
|
|
374
374
|
또는 거꾸로 탐색(negative look ahead)할 수도 있습니다.
|
375
375
|
|
376
376
|
```ruby
|
377
|
-
get %r{
|
377
|
+
get %r{(?!/index)} do
|
378
378
|
# ...
|
379
379
|
end
|
380
380
|
```
|
@@ -1991,7 +1991,7 @@ configure do
|
|
1991
1991
|
end
|
1992
1992
|
```
|
1993
1993
|
|
1994
|
-
환경(
|
1994
|
+
환경(APP_ENV 환경 변수)이 `:production`일 때만 실행되게 하려면 이렇게 하면 됩니다.
|
1995
1995
|
|
1996
1996
|
```ruby
|
1997
1997
|
configure :production do
|
@@ -2094,7 +2094,7 @@ set :protection, :session => true
|
|
2094
2094
|
|
2095
2095
|
<dt>environment</dt>
|
2096
2096
|
<dd>
|
2097
|
-
현재 환경, 기본값은 <tt>ENV['
|
2097
|
+
현재 환경, 기본값은 <tt>ENV['APP_ENV']</tt> ENV에 없을 경우엔 "development".
|
2098
2098
|
</dd>
|
2099
2099
|
|
2100
2100
|
<dt>logging</dt>
|
@@ -2225,16 +2225,16 @@ set :protection, :session => true
|
|
2225
2225
|
## 환경(Environments)
|
2226
2226
|
|
2227
2227
|
3가지의 미리 정의된 `environments` `"development"`, `"production"`, `"test"`
|
2228
|
-
가 있습니다. 환경은 `
|
2228
|
+
가 있습니다. 환경은 `APP_ENV` 환경 변수를 통해서도 설정됩니다. 기본값은
|
2229
2229
|
`"development"`입니다. `"development"` 모드에서는 모든 템플릿들은 요청 간에
|
2230
2230
|
리로드됩니다. 또, `"development"` 모드에서는 특별한 `not_found` 와 `error`
|
2231
2231
|
핸들러가 브라우저에서 스택 트레이스를 볼 수 있게합니다.
|
2232
2232
|
`"production"`과 `"test"`에서는 기본적으로 템플릿은 캐시됩니다.
|
2233
2233
|
|
2234
|
-
다른 환경으로 실행시키려면 `
|
2234
|
+
다른 환경으로 실행시키려면 `APP_ENV` 환경 변수를 사용하세요.
|
2235
2235
|
|
2236
2236
|
```shell
|
2237
|
-
|
2237
|
+
APP_ENV=production ruby my_app.rb
|
2238
2238
|
```
|
2239
2239
|
|
2240
2240
|
현재 설정된 환경이 무엇인지 검사하기 위해서는 준비된 `development?`, `test?`,
|
@@ -2400,7 +2400,7 @@ class MyAppTest < Minitest::Test
|
|
2400
2400
|
assert_equal 'Hello Frank!', last_response.body
|
2401
2401
|
end
|
2402
2402
|
|
2403
|
-
def
|
2403
|
+
def test_with_user_agent
|
2404
2404
|
get '/', {}, 'HTTP_USER_AGENT' => 'Songbird'
|
2405
2405
|
assert_equal "You're using Songbird!", last_response.body
|
2406
2406
|
end
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Sinatra
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/sinatra/sinatra.png)](http://travis-ci.org/sinatra/sinatra)
|
4
|
+
|
3
5
|
Sinatra is a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language) for
|
4
6
|
quickly creating web applications in Ruby with minimal effort:
|
5
7
|
|
@@ -73,6 +75,7 @@ pick up if available.
|
|
73
75
|
* [Filters](#filters)
|
74
76
|
* [Helpers](#helpers)
|
75
77
|
* [Using Sessions](#using-sessions)
|
78
|
+
* [Choosing Your Own Session Middleware](#choosing-your-own-session-middleware)
|
76
79
|
* [Halting](#halting)
|
77
80
|
* [Passing](#passing)
|
78
81
|
* [Triggering Another Route](#triggering-another-route)
|
@@ -160,6 +163,14 @@ end
|
|
160
163
|
Routes are matched in the order they are defined. The first route that
|
161
164
|
matches the request is invoked.
|
162
165
|
|
166
|
+
Routes with trailing slashes are different from the ones without:
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
get '/foo' do
|
170
|
+
# Does not match "GET /foo/"
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
163
174
|
Route patterns may include named parameters, accessible via the
|
164
175
|
`params` hash:
|
165
176
|
|
@@ -208,7 +219,7 @@ end
|
|
208
219
|
Route matching with Regular Expressions:
|
209
220
|
|
210
221
|
```ruby
|
211
|
-
get
|
222
|
+
get /\/hello\/([\w]+)/ do
|
212
223
|
"Hello, #{params['captures'].first}!"
|
213
224
|
end
|
214
225
|
```
|
@@ -384,7 +395,7 @@ end
|
|
384
395
|
Or, using negative look ahead:
|
385
396
|
|
386
397
|
```ruby
|
387
|
-
get %r{
|
398
|
+
get %r{(?!/index)} do
|
388
399
|
# ...
|
389
400
|
end
|
390
401
|
```
|
@@ -535,6 +546,14 @@ end
|
|
535
546
|
```
|
536
547
|
|
537
548
|
Renders the template string.
|
549
|
+
You can optionally specify `:path` and `:line` for a clearer backtrace if there is
|
550
|
+
a filesystem path or line associated with that string:
|
551
|
+
|
552
|
+
```ruby
|
553
|
+
get '/' do
|
554
|
+
haml '%div.title Hello World', :path => 'examples/file.haml', :line => 3
|
555
|
+
end
|
556
|
+
```
|
538
557
|
|
539
558
|
### Available Template Languages
|
540
559
|
|
@@ -718,7 +737,7 @@ template, you almost always want to pass locals to it.
|
|
718
737
|
</tr>
|
719
738
|
</table>
|
720
739
|
|
721
|
-
It is not possible to call methods from
|
740
|
+
It is not possible to call methods from Markdown, nor to pass locals to it.
|
722
741
|
You therefore will usually use it in combination with another rendering
|
723
742
|
engine:
|
724
743
|
|
@@ -754,7 +773,7 @@ template than for the layout by passing the `:layout_engine` option.
|
|
754
773
|
</tr>
|
755
774
|
</table>
|
756
775
|
|
757
|
-
It is not possible to call methods from
|
776
|
+
It is not possible to call methods from Textile, nor to pass locals to it. You
|
758
777
|
therefore will usually use it in combination with another rendering engine:
|
759
778
|
|
760
779
|
```ruby
|
@@ -789,7 +808,7 @@ template than for the layout by passing the `:layout_engine` option.
|
|
789
808
|
</tr>
|
790
809
|
</table>
|
791
810
|
|
792
|
-
It is not possible to call methods from
|
811
|
+
It is not possible to call methods from RDoc, nor to pass locals to it. You
|
793
812
|
therefore will usually use it in combination with another rendering engine:
|
794
813
|
|
795
814
|
```ruby
|
@@ -917,7 +936,7 @@ It also takes a block for inline templates (see example).
|
|
917
936
|
</tr>
|
918
937
|
</table>
|
919
938
|
|
920
|
-
It is not possible to call methods from
|
939
|
+
It is not possible to call methods from Creole, nor to pass locals to it. You
|
921
940
|
therefore will usually use it in combination with another rendering engine:
|
922
941
|
|
923
942
|
```ruby
|
@@ -1359,24 +1378,6 @@ get '/:value' do
|
|
1359
1378
|
end
|
1360
1379
|
```
|
1361
1380
|
|
1362
|
-
Note that `enable :sessions` actually stores all data in a cookie. This
|
1363
|
-
might not always be what you want (storing lots of data will increase your
|
1364
|
-
traffic, for instance). You can use any Rack session middleware: in order to
|
1365
|
-
do so, do **not** call `enable :sessions`, but instead pull in your
|
1366
|
-
middleware of choice as you would any other middleware:
|
1367
|
-
|
1368
|
-
```ruby
|
1369
|
-
use Rack::Session::Pool, :expire_after => 2592000
|
1370
|
-
|
1371
|
-
get '/' do
|
1372
|
-
"value = " << session[:value].inspect
|
1373
|
-
end
|
1374
|
-
|
1375
|
-
get '/:value' do
|
1376
|
-
session['value'] = params['value']
|
1377
|
-
end
|
1378
|
-
```
|
1379
|
-
|
1380
1381
|
To improve security, the session data in the cookie is signed with a session
|
1381
1382
|
secret. A random secret is generated for you by Sinatra. However, since this
|
1382
1383
|
secret will change with every start of your application, you might want to
|
@@ -1400,6 +1401,40 @@ domain with a *.* like this instead:
|
|
1400
1401
|
set :sessions, :domain => '.foo.com'
|
1401
1402
|
```
|
1402
1403
|
|
1404
|
+
#### Choosing Your Own Session Middleware
|
1405
|
+
|
1406
|
+
Note that `enable :sessions` actually stores all data in a cookie. This
|
1407
|
+
might not always be what you want (storing lots of data will increase your
|
1408
|
+
traffic, for instance). You can use any Rack session middleware: in order to
|
1409
|
+
do so, one of the following methods can be used:
|
1410
|
+
|
1411
|
+
```ruby
|
1412
|
+
enable :sessions
|
1413
|
+
set :session_store, Rack::Session::Pool
|
1414
|
+
```
|
1415
|
+
|
1416
|
+
Or to set up sessions with a hash of options:
|
1417
|
+
|
1418
|
+
```ruby
|
1419
|
+
set :sessions, :expire_after => 2592000
|
1420
|
+
set :session_store, Rack::Session::Pool
|
1421
|
+
```
|
1422
|
+
|
1423
|
+
Another option is to **not** call `enable :sessions`, but instead pull in your
|
1424
|
+
middleware of choice as you would any other middleware.
|
1425
|
+
|
1426
|
+
It is important to note that when using this method, session based protection **will not be enabled by default**.
|
1427
|
+
|
1428
|
+
The Rack middleware to do that will also need to be added:
|
1429
|
+
|
1430
|
+
```ruby
|
1431
|
+
use Rack::Session::Pool, :expire_after => 2592000
|
1432
|
+
use Rack::Protection::RemoteToken
|
1433
|
+
use Rack::Protection::SessionHijacking
|
1434
|
+
```
|
1435
|
+
|
1436
|
+
See 'Configuring attack protection' for more information.
|
1437
|
+
|
1403
1438
|
### Halting
|
1404
1439
|
|
1405
1440
|
To immediately stop a request within a filter or route use:
|
@@ -1581,6 +1616,10 @@ post '/:message' do
|
|
1581
1616
|
end
|
1582
1617
|
```
|
1583
1618
|
|
1619
|
+
It's also possible for the client to close the connection when trying to write
|
1620
|
+
to the socket. Because of this, it's recommended to check `out.closed?` before
|
1621
|
+
trying to write.
|
1622
|
+
|
1584
1623
|
### Logging
|
1585
1624
|
|
1586
1625
|
In the request scope, the `logger` helper exposes a `Logger` instance:
|
@@ -2021,7 +2060,7 @@ configure do
|
|
2021
2060
|
end
|
2022
2061
|
```
|
2023
2062
|
|
2024
|
-
Run only when the environment (`
|
2063
|
+
Run only when the environment (`APP_ENV` environment variable) is set to
|
2025
2064
|
`:production`:
|
2026
2065
|
|
2027
2066
|
```ruby
|
@@ -2076,12 +2115,12 @@ set :protection, :except => [:path_traversal, :session_hijacking]
|
|
2076
2115
|
```
|
2077
2116
|
|
2078
2117
|
By default, Sinatra will only set up session based protection if `:sessions`
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2118
|
+
have been enabled. See 'Using Sessions'. Sometimes you may want to set up
|
2119
|
+
sessions "outside" of the Sinatra app, such as in the config.ru or with a
|
2120
|
+
separate Rack::Builder instance. In that case you can still set up session
|
2121
|
+
based protection by passing the `:session` option:
|
2082
2122
|
|
2083
2123
|
```ruby
|
2084
|
-
use Rack::Session::Pool
|
2085
2124
|
set :protection, :session => true
|
2086
2125
|
```
|
2087
2126
|
|
@@ -2126,7 +2165,7 @@ set :protection, :session => true
|
|
2126
2165
|
|
2127
2166
|
<dt>environment</dt>
|
2128
2167
|
<dd>
|
2129
|
-
Current environment. Defaults to <tt>ENV['
|
2168
|
+
Current environment. Defaults to <tt>ENV['APP_ENV']</tt>, or
|
2130
2169
|
<tt>"development"</tt> if not available.
|
2131
2170
|
</dd>
|
2132
2171
|
|
@@ -2170,6 +2209,11 @@ set :protection, :session => true
|
|
2170
2209
|
<tt>app_file</tt> setting if not set.
|
2171
2210
|
</dd>
|
2172
2211
|
|
2212
|
+
<dt>quiet</dt>
|
2213
|
+
<dd>
|
2214
|
+
Disables logs generated by Sinatra's start and stop commands. `false` by default.
|
2215
|
+
</dd>
|
2216
|
+
|
2173
2217
|
<dt>reload_templates</dt>
|
2174
2218
|
<dd>
|
2175
2219
|
Whether or not to reload templates between requests. Enabled in development
|
@@ -2209,6 +2253,9 @@ set :protection, :session => true
|
|
2209
2253
|
See 'Using Sessions' section for more information.
|
2210
2254
|
</dd>
|
2211
2255
|
|
2256
|
+
<dt>session_store</dt>
|
2257
|
+
<dd>The Rack session middleware used. Defaults to <tt>Rack::Session::Cookie</tt>. See 'Using Sessions' section for more information.</dd>
|
2258
|
+
|
2212
2259
|
<dt>show_exceptions</dt>
|
2213
2260
|
<dd>
|
2214
2261
|
Show a stack trace in the browser when an exception happens. Enabled by
|
@@ -2264,16 +2311,16 @@ set :protection, :session => true
|
|
2264
2311
|
## Environments
|
2265
2312
|
|
2266
2313
|
There are three predefined `environments`: `"development"`, `"production"` and
|
2267
|
-
`"test"`. Environments can be set through the `
|
2314
|
+
`"test"`. Environments can be set through the `APP_ENV` environment variable.
|
2268
2315
|
The default value is `"development"`. In the `"development"` environment all
|
2269
2316
|
templates are reloaded between requests, and special `not_found` and `error`
|
2270
2317
|
handlers display stack traces in your browser. In the `"production"` and
|
2271
2318
|
`"test"` environments, templates are cached by default.
|
2272
2319
|
|
2273
|
-
To run different environments, set the `
|
2320
|
+
To run different environments, set the `APP_ENV` environment variable:
|
2274
2321
|
|
2275
2322
|
```shell
|
2276
|
-
|
2323
|
+
APP_ENV=production ruby my_app.rb
|
2277
2324
|
```
|
2278
2325
|
|
2279
2326
|
You can use predefined methods: `development?`, `test?` and `production?` to
|
@@ -2442,7 +2489,7 @@ class MyAppTest < Minitest::Test
|
|
2442
2489
|
assert_equal 'Hello Frank!', last_response.body
|
2443
2490
|
end
|
2444
2491
|
|
2445
|
-
def
|
2492
|
+
def test_with_user_agent
|
2446
2493
|
get '/', {}, 'HTTP_USER_AGENT' => 'Songbird'
|
2447
2494
|
assert_equal "You're using Songbird!", last_response.body
|
2448
2495
|
end
|
@@ -2817,7 +2864,7 @@ being [extending the main object](https://github.com/sinatra/sinatra/blob/ca0636
|
|
2817
2864
|
Sinatra applications can be run directly:
|
2818
2865
|
|
2819
2866
|
```shell
|
2820
|
-
ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
|
2867
|
+
ruby myapp.rb [-h] [-x] [-q] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
|
2821
2868
|
```
|
2822
2869
|
|
2823
2870
|
Options are:
|
@@ -2828,6 +2875,7 @@ Options are:
|
|
2828
2875
|
-o # set the host (default is 0.0.0.0)
|
2829
2876
|
-e # set the environment (default is development)
|
2830
2877
|
-s # specify rack server/handler (default is thin)
|
2878
|
+
-q # turn on quiet mode for server (default is off)
|
2831
2879
|
-x # turn on the mutex lock (default is off)
|
2832
2880
|
```
|
2833
2881
|
|
@@ -2871,31 +2919,10 @@ thin --threaded start
|
|
2871
2919
|
|
2872
2920
|
The following Ruby versions are officially supported:
|
2873
2921
|
<dl>
|
2874
|
-
<dt>Ruby
|
2875
|
-
<dd>
|
2876
|
-
1.8.7 is fully supported, however, if nothing is keeping you from it, we
|
2877
|
-
recommend upgrading or switching to JRuby or Rubinius. Support for 1.8.7
|
2878
|
-
will not be dropped before Sinatra 2.0. Ruby 1.8.6 is no longer supported.
|
2879
|
-
</dd>
|
2880
|
-
|
2881
|
-
<dt>Ruby 1.9.2</dt>
|
2922
|
+
<dt>Ruby 2.2</dt>
|
2882
2923
|
<dd>
|
2883
|
-
|
2884
|
-
|
2885
|
-
at least until the release of Sinatra 1.5.
|
2886
|
-
</dd>
|
2887
|
-
|
2888
|
-
<dt>Ruby 1.9.3</dt>
|
2889
|
-
<dd>
|
2890
|
-
1.9.3 is fully supported and recommended. Please note that switching to 1.9.3
|
2891
|
-
from an earlier version will invalidate all sessions. 1.9.3 will be supported
|
2892
|
-
until the release of Sinatra 2.0.
|
2893
|
-
</dd>
|
2894
|
-
|
2895
|
-
<dt>Ruby 2.x</dt>
|
2896
|
-
<dd>
|
2897
|
-
2.x is fully supported and recommended. There are currently no plans to drop
|
2898
|
-
official support for it.
|
2924
|
+
2.2 is fully supported and recommended. There are currently no plans to
|
2925
|
+
drop official support for it.
|
2899
2926
|
</dd>
|
2900
2927
|
|
2901
2928
|
<dt>Rubinius</dt>
|
@@ -2912,6 +2939,8 @@ The following Ruby versions are officially supported:
|
|
2912
2939
|
</dd>
|
2913
2940
|
</dl>
|
2914
2941
|
|
2942
|
+
Versions of Ruby prior to 2.2.2 are no longer supported as of Sinatra 2.0.
|
2943
|
+
|
2915
2944
|
We also keep an eye on upcoming Ruby versions.
|
2916
2945
|
|
2917
2946
|
The following Ruby implementations are not officially supported but still are
|
@@ -2935,7 +2964,7 @@ implementation.
|
|
2935
2964
|
If you run MacRuby, you should `gem install control_tower`.
|
2936
2965
|
|
2937
2966
|
Sinatra currently doesn't run on Cardinal, SmallRuby, BlueRuby or any
|
2938
|
-
Ruby version prior to
|
2967
|
+
Ruby version prior to 2.2.
|
2939
2968
|
|
2940
2969
|
## The Bleeding Edge
|
2941
2970
|
|
@@ -2965,7 +2994,7 @@ Then, in your project directory, create a `Gemfile`:
|
|
2965
2994
|
|
2966
2995
|
```ruby
|
2967
2996
|
source 'https://rubygems.org'
|
2968
|
-
gem 'sinatra', :github =>
|
2997
|
+
gem 'sinatra', :github => 'sinatra/sinatra'
|
2969
2998
|
|
2970
2999
|
# other dependencies
|
2971
3000
|
gem 'haml' # for instance, if you use haml
|