sinatra 2.0.0 → 2.0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/AUTHORS.md +1 -0
- data/CHANGELOG.md +157 -37
- data/CONTRIBUTING.md +7 -7
- data/Gemfile +10 -2
- data/README.de.md +6 -6
- data/README.es.md +733 -352
- data/README.fr.md +6 -6
- data/README.ja.md +22 -22
- data/README.ko.md +6 -6
- data/README.malayalam.md +3141 -0
- data/README.md +75 -56
- data/README.pt-br.md +2359 -332
- data/README.ru.md +834 -563
- data/README.zh.md +82 -20
- data/Rakefile +10 -7
- data/VERSION +1 -0
- data/lib/sinatra/base.rb +51 -55
- data/lib/sinatra/indifferent_hash.rb +65 -15
- data/lib/sinatra/main.rb +30 -11
- data/lib/sinatra/show_exceptions.rb +43 -11
- data/lib/sinatra/version.rb +1 -1
- data/sinatra.gemspec +26 -2
- metadata +16 -7
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Sinatra
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/sinatra)
|
4
|
+
[](https://travis-ci.org/sinatra/sinatra)
|
5
|
+
[](https://dependabot.com/compatibility-score.html?dependency-name=sinatra&package-manager=bundler&version-scheme=semver)
|
4
6
|
|
5
7
|
Sinatra is a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language) for
|
6
8
|
quickly creating web applications in Ruby with minimal effort:
|
@@ -28,6 +30,10 @@ ruby myapp.rb
|
|
28
30
|
|
29
31
|
View at: [http://localhost:4567](http://localhost:4567)
|
30
32
|
|
33
|
+
The code you changed will not take effect until you restart the server.
|
34
|
+
Please restart the server every time you change or use
|
35
|
+
[sinatra/reloader](http://www.sinatrarb.com/contrib/reloader).
|
36
|
+
|
31
37
|
It is recommended to also run `gem install thin`, which Sinatra will
|
32
38
|
pick up if available.
|
33
39
|
|
@@ -75,9 +81,9 @@ pick up if available.
|
|
75
81
|
* [Filters](#filters)
|
76
82
|
* [Helpers](#helpers)
|
77
83
|
* [Using Sessions](#using-sessions)
|
78
|
-
|
79
|
-
|
80
|
-
|
84
|
+
* [Session Secret Security](#session-secret-security)
|
85
|
+
* [Session Config](#session-config)
|
86
|
+
* [Choosing Your Own Session Middleware](#choosing-your-own-session-middleware)
|
81
87
|
* [Halting](#halting)
|
82
88
|
* [Passing](#passing)
|
83
89
|
* [Triggering Another Route](#triggering-another-route)
|
@@ -253,11 +259,11 @@ end
|
|
253
259
|
```
|
254
260
|
|
255
261
|
By the way, unless you disable the path traversal attack protection (see
|
256
|
-
below), the request path might be modified before
|
257
|
-
routes.
|
262
|
+
[below](#configuring-attack-protection)), the request path might be modified before
|
263
|
+
matching against your routes.
|
258
264
|
|
259
|
-
You may customize the Mustermann
|
260
|
-
`:mustermann_opts` hash:
|
265
|
+
You may customize the [Mustermann](https://github.com/sinatra/mustermann#readme)
|
266
|
+
options used for a given route by passing in a `:mustermann_opts` hash:
|
261
267
|
|
262
268
|
```ruby
|
263
269
|
get '\A/posts\z', :mustermann_opts => { :type => :regexp, :check_anchors => false } do
|
@@ -345,13 +351,13 @@ But other values are also accepted.
|
|
345
351
|
You can return any object that would either be a valid Rack response, Rack
|
346
352
|
body object or HTTP status code:
|
347
353
|
|
348
|
-
* An Array with three elements: `[status (
|
354
|
+
* An Array with three elements: `[status (Integer), headers (Hash), response
|
349
355
|
body (responds to #each)]`
|
350
|
-
* An Array with two elements: `[status (
|
356
|
+
* An Array with two elements: `[status (Integer), response body (responds to
|
351
357
|
#each)]`
|
352
358
|
* An object that responds to `#each` and passes nothing but strings to
|
353
359
|
the given block
|
354
|
-
* A
|
360
|
+
* A Integer representing the status code
|
355
361
|
|
356
362
|
That way we can, for instance, easily implement a streaming example:
|
357
363
|
|
@@ -365,7 +371,7 @@ end
|
|
365
371
|
get('/') { Stream.new }
|
366
372
|
```
|
367
373
|
|
368
|
-
You can also use the `stream` helper method (described below) to reduce
|
374
|
+
You can also use the `stream` helper method ([described below](#streaming-responses)) to reduce
|
369
375
|
boiler plate and embed the streaming logic in the route.
|
370
376
|
|
371
377
|
## Custom Route Matchers
|
@@ -428,7 +434,7 @@ Note that the public directory name is not included in the URL. A file
|
|
428
434
|
`./public/css/style.css` is made available as
|
429
435
|
`http://example.com/css/style.css`.
|
430
436
|
|
431
|
-
Use the `:static_cache_control` setting (see below) to add
|
437
|
+
Use the `:static_cache_control` setting (see [below](#cache-control)) to add
|
432
438
|
`Cache-Control` header info.
|
433
439
|
|
434
440
|
## Views / Templates
|
@@ -605,13 +611,15 @@ get('/') { markdown :index }
|
|
605
611
|
<tr>
|
606
612
|
<td>Dependency</td>
|
607
613
|
<td>
|
608
|
-
<a href="
|
614
|
+
<a href="https://github.com/jeremyevans/erubi" title="erubi">erubi</a>
|
615
|
+
or <a href="http://www.kuwata-lab.com/erubis/" title="erubis">erubis</a>
|
609
616
|
or erb (included in Ruby)
|
610
617
|
</td>
|
611
618
|
</tr>
|
612
619
|
<tr>
|
613
620
|
<td>File Extensions</td>
|
614
|
-
<td><tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.
|
621
|
+
<td><tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.erubi</tt> (Erubi only)
|
622
|
+
or <tt>.erubis</tt> (Erubis only)</td>
|
615
623
|
</tr>
|
616
624
|
<tr>
|
617
625
|
<td>Example</td>
|
@@ -638,7 +646,7 @@ get('/') { markdown :index }
|
|
638
646
|
</tr>
|
639
647
|
</table>
|
640
648
|
|
641
|
-
It also takes a block for inline templates (see example).
|
649
|
+
It also takes a block for inline templates (see [example](#inline-templates)).
|
642
650
|
|
643
651
|
#### Nokogiri Templates
|
644
652
|
|
@@ -657,14 +665,14 @@ It also takes a block for inline templates (see example).
|
|
657
665
|
</tr>
|
658
666
|
</table>
|
659
667
|
|
660
|
-
It also takes a block for inline templates (see example).
|
668
|
+
It also takes a block for inline templates (see [example](#inline-templates)).
|
661
669
|
|
662
670
|
#### Sass Templates
|
663
671
|
|
664
672
|
<table>
|
665
673
|
<tr>
|
666
674
|
<td>Dependency</td>
|
667
|
-
<td><a href="
|
675
|
+
<td><a href="https://sass-lang.com/" title="sass">sass</a></td>
|
668
676
|
</tr>
|
669
677
|
<tr>
|
670
678
|
<td>File Extension</td>
|
@@ -681,7 +689,7 @@ It also takes a block for inline templates (see example).
|
|
681
689
|
<table>
|
682
690
|
<tr>
|
683
691
|
<td>Dependency</td>
|
684
|
-
<td><a href="
|
692
|
+
<td><a href="https://sass-lang.com/" title="sass">sass</a></td>
|
685
693
|
</tr>
|
686
694
|
<tr>
|
687
695
|
<td>File Extension</td>
|
@@ -715,7 +723,7 @@ It also takes a block for inline templates (see example).
|
|
715
723
|
<table>
|
716
724
|
<tr>
|
717
725
|
<td>Dependency</td>
|
718
|
-
<td><a href="
|
726
|
+
<td><a href="https://shopify.github.io/liquid/" title="liquid">liquid</a></td>
|
719
727
|
</tr>
|
720
728
|
<tr>
|
721
729
|
<td>File Extension</td>
|
@@ -739,9 +747,11 @@ template, you almost always want to pass locals to it.
|
|
739
747
|
Anyone of:
|
740
748
|
<a href="https://github.com/davidfstr/rdiscount" title="RDiscount">RDiscount</a>,
|
741
749
|
<a href="https://github.com/vmg/redcarpet" title="RedCarpet">RedCarpet</a>,
|
742
|
-
<a href="
|
743
|
-
<a href="
|
750
|
+
<a href="https://github.com/ged/bluecloth" title="BlueCloth">BlueCloth</a>,
|
751
|
+
<a href="https://kramdown.gettalong.org/" title="kramdown">kramdown</a>,
|
744
752
|
<a href="https://github.com/bhollis/maruku" title="maruku">maruku</a>
|
753
|
+
<a href="https://github.com/gjtorikian/commonmarker" title="commonmarker">commonmarker</a>
|
754
|
+
<a href="https://github.com/alphabetum/pandoc-ruby" title="pandoc">pandoc</a>
|
745
755
|
</td>
|
746
756
|
</tr>
|
747
757
|
<tr>
|
@@ -890,7 +900,7 @@ almost always want to pass locals to it.
|
|
890
900
|
<table>
|
891
901
|
<tr>
|
892
902
|
<td>Dependency</td>
|
893
|
-
<td><a href="
|
903
|
+
<td><a href="https://markaby.github.io/" title="Markaby">Markaby</a></td>
|
894
904
|
</tr>
|
895
905
|
<tr>
|
896
906
|
<td>File Extension</td>
|
@@ -902,7 +912,7 @@ almost always want to pass locals to it.
|
|
902
912
|
</tr>
|
903
913
|
</table>
|
904
914
|
|
905
|
-
It also takes a block for inline templates (see example).
|
915
|
+
It also takes a block for inline templates (see [example](#inline-templates)).
|
906
916
|
|
907
917
|
#### RABL Templates
|
908
918
|
|
@@ -1019,7 +1029,7 @@ template than for the layout by passing the `:layout_engine` option.
|
|
1019
1029
|
<a href="https://github.com/josh/ruby-coffee-script" title="Ruby CoffeeScript">
|
1020
1030
|
CoffeeScript
|
1021
1031
|
</a> and a
|
1022
|
-
<a href="https://github.com/sstephenson/execjs
|
1032
|
+
<a href="https://github.com/sstephenson/execjs" title="ExecJS">
|
1023
1033
|
way to execute javascript
|
1024
1034
|
</a>
|
1025
1035
|
</td>
|
@@ -1043,7 +1053,7 @@ template than for the layout by passing the `:layout_engine` option.
|
|
1043
1053
|
<a href="https://github.com/forgecrafted/ruby-stylus" title="Ruby Stylus">
|
1044
1054
|
Stylus
|
1045
1055
|
</a> and a
|
1046
|
-
<a href="https://github.com/sstephenson/execjs
|
1056
|
+
<a href="https://github.com/sstephenson/execjs" title="ExecJS">
|
1047
1057
|
way to execute javascript
|
1048
1058
|
</a>
|
1049
1059
|
</td>
|
@@ -1117,7 +1127,7 @@ present(resource);
|
|
1117
1127
|
<table>
|
1118
1128
|
<tr>
|
1119
1129
|
<td>Dependency</td>
|
1120
|
-
<td><a href="https://github.com/blambeau/wlang
|
1130
|
+
<td><a href="https://github.com/blambeau/wlang" title="WLang">WLang</a></td>
|
1121
1131
|
</tr>
|
1122
1132
|
<tr>
|
1123
1133
|
<td>File Extension</td>
|
@@ -1273,8 +1283,8 @@ get '/' do
|
|
1273
1283
|
end
|
1274
1284
|
```
|
1275
1285
|
|
1276
|
-
Renders `./views/index.myat`.
|
1277
|
-
|
1286
|
+
Renders `./views/index.myat`. Learn more about
|
1287
|
+
[Tilt](https://github.com/rtomayko/tilt#readme).
|
1278
1288
|
|
1279
1289
|
### Using Custom Logic for Template Lookup
|
1280
1290
|
|
@@ -1435,8 +1445,8 @@ $ ruby -e "require 'securerandom'; puts SecureRandom.hex(64)"
|
|
1435
1445
|
|
1436
1446
|
**Session Secret Generation (Bonus Points)**
|
1437
1447
|
|
1438
|
-
Use the [sysrandom gem](https://github.com/cryptosphere/sysrandom) to
|
1439
|
-
use of system RNG facilities to generate random values instead of
|
1448
|
+
Use the [sysrandom gem](https://github.com/cryptosphere/sysrandom#readme) to
|
1449
|
+
prefer use of system RNG facilities to generate random values instead of
|
1440
1450
|
userspace `OpenSSL` which MRI Ruby currently defaults to:
|
1441
1451
|
|
1442
1452
|
```text
|
@@ -1466,7 +1476,7 @@ Setup your app config to fail-safe to a secure random secret
|
|
1466
1476
|
if the `SESSION_SECRET` environment variable is not available.
|
1467
1477
|
|
1468
1478
|
For bonus points use the [sysrandom
|
1469
|
-
gem](https://github.com/cryptosphere/sysrandom) here as well:
|
1479
|
+
gem](https://github.com/cryptosphere/sysrandom#readme) here as well:
|
1470
1480
|
|
1471
1481
|
```ruby
|
1472
1482
|
require 'securerandom'
|
@@ -1523,7 +1533,7 @@ use Rack::Protection::RemoteToken
|
|
1523
1533
|
use Rack::Protection::SessionHijacking
|
1524
1534
|
```
|
1525
1535
|
|
1526
|
-
See 'Configuring attack protection' for more information.
|
1536
|
+
See '[Configuring attack protection](#configuring-attack-protection)' for more information.
|
1527
1537
|
|
1528
1538
|
### Halting
|
1529
1539
|
|
@@ -1625,7 +1635,7 @@ end
|
|
1625
1635
|
```
|
1626
1636
|
|
1627
1637
|
It is also possible to pass a block to `body`, which will be executed by the
|
1628
|
-
Rack handler (this can be used to implement streaming, see "Return Values").
|
1638
|
+
Rack handler (this can be used to implement streaming, [see "Return Values"](#return-values)).
|
1629
1639
|
|
1630
1640
|
Similar to the body, you can also set the status code and headers:
|
1631
1641
|
|
@@ -1634,7 +1644,7 @@ get '/foo' do
|
|
1634
1644
|
status 418
|
1635
1645
|
headers \
|
1636
1646
|
"Allow" => "BREW, POST, GET, PROPFIND, WHEN",
|
1637
|
-
"Refresh" => "Refresh: 20;
|
1647
|
+
"Refresh" => "Refresh: 20; https://ietf.org/rfc/rfc2324.txt"
|
1638
1648
|
body "I'm a tea pot!"
|
1639
1649
|
end
|
1640
1650
|
```
|
@@ -1773,7 +1783,7 @@ Haml:
|
|
1773
1783
|
|
1774
1784
|
It takes reverse proxies and Rack routers into account, if present.
|
1775
1785
|
|
1776
|
-
This method is also aliased to `to` (see below for an example).
|
1786
|
+
This method is also aliased to `to` (see [below](#browser-redirect) for an example).
|
1777
1787
|
|
1778
1788
|
### Browser Redirect
|
1779
1789
|
|
@@ -1881,7 +1891,7 @@ etag @article.sha1, :weak
|
|
1881
1891
|
These helpers will not do any caching for you, but rather feed the necessary
|
1882
1892
|
information to your cache. If you are looking for a quick
|
1883
1893
|
reverse-proxy caching solution, try
|
1884
|
-
[rack-cache](https://github.com/rtomayko/rack-cache):
|
1894
|
+
[rack-cache](https://github.com/rtomayko/rack-cache#readme):
|
1885
1895
|
|
1886
1896
|
```ruby
|
1887
1897
|
require "rack/cache"
|
@@ -1896,7 +1906,7 @@ get '/' do
|
|
1896
1906
|
end
|
1897
1907
|
```
|
1898
1908
|
|
1899
|
-
Use the `:static_cache_control` setting (see below) to add
|
1909
|
+
Use the `:static_cache_control` setting (see [below](#cache-control)) to add
|
1900
1910
|
`Cache-Control` header info to static files.
|
1901
1911
|
|
1902
1912
|
According to RFC 2616, your application should behave differently if the
|
@@ -2187,7 +2197,7 @@ end
|
|
2187
2197
|
### Configuring attack protection
|
2188
2198
|
|
2189
2199
|
Sinatra is using
|
2190
|
-
[Rack::Protection](https://github.com/sinatra/rack-protection#readme) to
|
2200
|
+
[Rack::Protection](https://github.com/sinatra/sinatra/tree/master/rack-protection#readme) to
|
2191
2201
|
defend your application against common, opportunistic attacks. You can
|
2192
2202
|
easily disable this behavior (which will open up your application to tons
|
2193
2203
|
of common vulnerabilities):
|
@@ -2208,7 +2218,7 @@ set :protection, :except => [:path_traversal, :session_hijacking]
|
|
2208
2218
|
```
|
2209
2219
|
|
2210
2220
|
By default, Sinatra will only set up session based protection if `:sessions`
|
2211
|
-
have been enabled. See 'Using Sessions'. Sometimes you may want to set up
|
2221
|
+
have been enabled. See '[Using Sessions](#using-sessions)'. Sometimes you may want to set up
|
2212
2222
|
sessions "outside" of the Sinatra app, such as in the config.ru or with a
|
2213
2223
|
separate `Rack::Builder` instance. In that case you can still set up session
|
2214
2224
|
based protection by passing the `:session` option:
|
@@ -2353,6 +2363,16 @@ set :protection, :session => true
|
|
2353
2363
|
priority, default depends on Ruby implementation.
|
2354
2364
|
</dd>
|
2355
2365
|
|
2366
|
+
<dt>server_settings</dt>
|
2367
|
+
<dd>
|
2368
|
+
If you are using a WEBrick web server, presumably for your development
|
2369
|
+
environment, you can pass a hash of options to <tt>server_settings</tt>,
|
2370
|
+
such as <tt>SSLEnable</tt> or <tt>SSLVerifyClient</tt>. However, web
|
2371
|
+
servers such as Puma and Thin do not support this, so you can set
|
2372
|
+
<tt>server_settings</tt> by defining it as a method when you call
|
2373
|
+
<tt>configure</tt>.
|
2374
|
+
</dd>
|
2375
|
+
|
2356
2376
|
<dt>sessions</dt>
|
2357
2377
|
<dd>
|
2358
2378
|
Enable cookie-based sessions support using
|
@@ -2531,7 +2551,7 @@ and additional debugging information in your browser.
|
|
2531
2551
|
|
2532
2552
|
## Rack Middleware
|
2533
2553
|
|
2534
|
-
Sinatra rides on [Rack](
|
2554
|
+
Sinatra rides on [Rack](https://rack.github.io/), a minimal standard
|
2535
2555
|
interface for Ruby web frameworks. One of Rack's most interesting
|
2536
2556
|
capabilities for application developers is support for "middleware" --
|
2537
2557
|
components that sit between the server and your application monitoring
|
@@ -2571,7 +2591,7 @@ typically don't have to `use` them explicitly.
|
|
2571
2591
|
|
2572
2592
|
You can find useful middleware in
|
2573
2593
|
[rack](https://github.com/rack/rack/tree/master/lib/rack),
|
2574
|
-
[rack-contrib](https://github.com/rack/rack-contrib#
|
2594
|
+
[rack-contrib](https://github.com/rack/rack-contrib#readme),
|
2575
2595
|
or in the [Rack wiki](https://github.com/rack/rack/wiki/List-of-Middleware).
|
2576
2596
|
|
2577
2597
|
## Testing
|
@@ -2995,7 +3015,9 @@ Options are:
|
|
2995
3015
|
|
2996
3016
|
### Multi-threading
|
2997
3017
|
|
2998
|
-
_Paraphrasing from
|
3018
|
+
_Paraphrasing from
|
3019
|
+
[this StackOverflow answer](https://stackoverflow.com/a/6282999/5245129)
|
3020
|
+
by Konstantin_
|
2999
3021
|
|
3000
3022
|
Sinatra doesn't impose any concurrency model, but leaves that to the
|
3001
3023
|
underlying Rack handler (server) like Thin, Puma or WEBrick. Sinatra
|
@@ -3026,9 +3048,6 @@ To start the server, the command would be:
|
|
3026
3048
|
thin --threaded start
|
3027
3049
|
```
|
3028
3050
|
|
3029
|
-
|
3030
|
-
[so-answer]: http://stackoverflow.com/questions/6278817/is-sinatra-multi-threaded/6282999#6282999)
|
3031
|
-
|
3032
3051
|
## Requirement
|
3033
3052
|
|
3034
3053
|
The following Ruby versions are officially supported:
|
@@ -3097,7 +3116,7 @@ to get some of the latest features.
|
|
3097
3116
|
### With Bundler
|
3098
3117
|
|
3099
3118
|
If you want to run your application with the latest Sinatra, using
|
3100
|
-
[Bundler](
|
3119
|
+
[Bundler](https://bundler.io) is the recommended way.
|
3101
3120
|
|
3102
3121
|
First, install bundler, if you haven't:
|
3103
3122
|
|
@@ -3127,7 +3146,7 @@ bundle exec ruby myapp.rb
|
|
3127
3146
|
|
3128
3147
|
## Versioning
|
3129
3148
|
|
3130
|
-
Sinatra follows [Semantic Versioning](
|
3149
|
+
Sinatra follows [Semantic Versioning](https://semver.org/), both SemVer and
|
3131
3150
|
SemVerTag.
|
3132
3151
|
|
3133
3152
|
## Further Reading
|
@@ -3138,14 +3157,14 @@ SemVerTag.
|
|
3138
3157
|
help? Have a patch?
|
3139
3158
|
* [Issue tracker](https://github.com/sinatra/sinatra/issues)
|
3140
3159
|
* [Twitter](https://twitter.com/sinatra)
|
3141
|
-
* [Mailing List](
|
3142
|
-
* IRC: [#sinatra](irc://chat.freenode.net/#sinatra) on
|
3143
|
-
* [Sinatra & Friends](https://sinatrarb.slack.com) on Slack
|
3144
|
-
[
|
3145
|
-
* [Sinatra Book](https://github.com/sinatra/sinatra-book
|
3146
|
-
* [Sinatra Recipes](http://recipes.sinatrarb.com/) Community
|
3147
|
-
|
3160
|
+
* [Mailing List](https://groups.google.com/forum/#!forum/sinatrarb)
|
3161
|
+
* IRC: [#sinatra](irc://chat.freenode.net/#sinatra) on [Freenode](https://freenode.net)
|
3162
|
+
* [Sinatra & Friends](https://sinatrarb.slack.com) on Slack
|
3163
|
+
([get an invite](https://sinatra-slack.herokuapp.com/))
|
3164
|
+
* [Sinatra Book](https://github.com/sinatra/sinatra-book) - Cookbook Tutorial
|
3165
|
+
* [Sinatra Recipes](http://recipes.sinatrarb.com/) - Community contributed
|
3166
|
+
recipes
|
3148
3167
|
* API documentation for the [latest release](http://www.rubydoc.info/gems/sinatra)
|
3149
3168
|
or the [current HEAD](http://www.rubydoc.info/github/sinatra/sinatra) on
|
3150
|
-
http://www.rubydoc.info/
|
3169
|
+
[RubyDoc](http://www.rubydoc.info/)
|
3151
3170
|
* [CI server](https://travis-ci.org/sinatra/sinatra)
|