sinatra 1.2.9 → 1.3.0.a
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.
- data/CHANGES +12 -118
- data/Gemfile +23 -37
- data/LICENSE +1 -1
- data/README.de.rdoc +11 -15
- data/README.es.rdoc +50 -76
- data/README.fr.rdoc +7 -7
- data/README.hu.rdoc +1 -1
- data/README.jp.rdoc +2 -8
- data/README.pt-br.rdoc +1 -1
- data/README.pt-pt.rdoc +1 -1
- data/README.rdoc +64 -139
- data/README.ru.rdoc +618 -68
- data/README.zh.rdoc +7 -7
- data/Rakefile +6 -29
- data/lib/sinatra.rb +3 -0
- data/lib/sinatra/base.rb +115 -179
- data/lib/sinatra/main.rb +1 -1
- data/lib/sinatra/rack.rb +44 -0
- data/lib/sinatra/showexceptions.rb +3 -3
- data/sinatra.gemspec +5 -4
- data/test/coffee_test.rb +11 -15
- data/test/delegator_test.rb +3 -43
- data/test/helper.rb +0 -4
- data/test/helpers_test.rb +44 -37
- data/test/nokogiri_test.rb +6 -5
- data/test/result_test.rb +4 -4
- data/test/routing_test.rb +8 -132
- data/test/server_test.rb +2 -3
- data/test/settings_test.rb +0 -26
- data/test/slim_test.rb +25 -15
- data/test/static_test.rb +1 -0
- metadata +17 -67
- data/test/rack_test.rb +0 -45
data/README.fr.rdoc
CHANGED
@@ -894,8 +894,8 @@ souhaitez obtenir le résultat d'une autre route. Pour cela, utilisez
|
|
894
894
|
simplement +call+ :
|
895
895
|
|
896
896
|
get '/foo' do
|
897
|
-
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
898
|
-
[status,
|
897
|
+
status, headers, body = call request.env.merge("PATH_INFO" => '/bar')
|
898
|
+
[status, body.upcase]
|
899
899
|
end
|
900
900
|
|
901
901
|
get '/bar' do
|
@@ -940,7 +940,7 @@ retour et les entêtes :
|
|
940
940
|
get '/foo' do
|
941
941
|
status 418
|
942
942
|
headers \
|
943
|
-
"Allow" => "BREW, POST, GET, PROPFIND, WHEN"
|
943
|
+
"Allow" => "BREW, POST, GET, PROPFIND, WHEN"
|
944
944
|
"Refresh" => "Refresh: 20; http://www.ietf.org/rfc/rfc2324.txt"
|
945
945
|
body "I'm a tea pot!"
|
946
946
|
end
|
@@ -1008,7 +1008,7 @@ Pour passer des arguments à une redirection, ajoutez-les soit à la requête :
|
|
1008
1008
|
|
1009
1009
|
Ou bien utilisez une session :
|
1010
1010
|
|
1011
|
-
enable :
|
1011
|
+
enable :session
|
1012
1012
|
|
1013
1013
|
get '/foo' do
|
1014
1014
|
session[:secret] = 'foo'
|
@@ -1399,7 +1399,7 @@ variable Rack <tt>sinatra.error</tt>:
|
|
1399
1399
|
Erreur sur mesure:
|
1400
1400
|
|
1401
1401
|
error MonErreurSurMesure do
|
1402
|
-
'Donc il est arrivé ceci...' + env['sinatra.error'].message
|
1402
|
+
'Donc il est arrivé ceci...' + request.env['sinatra.error'].message
|
1403
1403
|
end
|
1404
1404
|
|
1405
1405
|
Donc si ceci arrive:
|
@@ -1595,7 +1595,7 @@ Ou alors avec un fichier <tt>config.ru</tt>, qui permet d'utiliser n'importe
|
|
1595
1595
|
quel gestionnaire Rack :
|
1596
1596
|
|
1597
1597
|
# config.ru
|
1598
|
-
require '
|
1598
|
+
require 'my_app'
|
1599
1599
|
run MyApp
|
1600
1600
|
|
1601
1601
|
Exécutez :
|
@@ -1615,7 +1615,7 @@ Ecrivez votre application :
|
|
1615
1615
|
|
1616
1616
|
Et un fichier <tt>config.ru</tt> correspondant :
|
1617
1617
|
|
1618
|
-
require '
|
1618
|
+
require 'app'
|
1619
1619
|
run Sinatra::Application
|
1620
1620
|
|
1621
1621
|
=== Quand utiliser un fichier config.ru ?
|
data/README.hu.rdoc
CHANGED
@@ -399,7 +399,7 @@ előszűrő kivételt vált ki. A kivétel objektum lehívható a
|
|
399
399
|
Egyéni hibakezelés:
|
400
400
|
|
401
401
|
error MyCustomError do
|
402
|
-
'Szóval az van, hogy...' + env['sinatra.error'].message
|
402
|
+
'Szóval az van, hogy...' + request.env['sinatra.error'].message
|
403
403
|
end
|
404
404
|
|
405
405
|
És amikor fellép:
|
data/README.jp.rdoc
CHANGED
@@ -67,12 +67,6 @@ Sinatraでは、ルートはHTTPメソッドとURLマッチングパターンが
|
|
67
67
|
params[:splat] # => ["path/to/file", "xml"]
|
68
68
|
end
|
69
69
|
|
70
|
-
ブロックパラーメータを使用した場合:
|
71
|
-
|
72
|
-
get '/download/*.*' do |path, ext|
|
73
|
-
[path, ext] # => ["path/to/file", "xml"]
|
74
|
-
end
|
75
|
-
|
76
70
|
正規表現を使ったルート:
|
77
71
|
|
78
72
|
get %r{/hello/([\w]+)} do
|
@@ -706,7 +700,7 @@ body部を指定することもできます ...
|
|
706
700
|
エラーをカスタマイズする場合は、
|
707
701
|
|
708
702
|
error MyCustomError do
|
709
|
-
'エラーメッセージ...' + env['sinatra.error'].message
|
703
|
+
'エラーメッセージ...' + request.env['sinatra.error'].message
|
710
704
|
end
|
711
705
|
|
712
706
|
と書いておいて,下記のように呼び出します。
|
@@ -996,7 +990,7 @@ Sinatraの開発版を使いたい場合は、ローカルに開発版を落と
|
|
996
990
|
git clone git://github.com/sinatra/sinatra.git
|
997
991
|
ruby -Isinatra/lib myapp.rb
|
998
992
|
|
999
|
-
<tt>sinatra/lib</tt
|
993
|
+
<tt>sinatra/lib</tt>ディレクトリをto the<tt>LOAD_PATH</tt>に追加する方法もあります。
|
1000
994
|
|
1001
995
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/sinatra/lib'
|
1002
996
|
require 'rubygems'
|
data/README.pt-br.rdoc
CHANGED
@@ -431,7 +431,7 @@ Rack <tt>sinatra.error</tt>:
|
|
431
431
|
Erros customizados:
|
432
432
|
|
433
433
|
error MeuErroCustomizado do
|
434
|
-
'Então que aconteceu foi...' + env['sinatra.error'].message
|
434
|
+
'Então que aconteceu foi...' + request.env['sinatra.error'].message
|
435
435
|
end
|
436
436
|
|
437
437
|
Então, se isso acontecer:
|
data/README.pt-pt.rdoc
CHANGED
@@ -430,7 +430,7 @@ Rack <tt>sinatra.error</tt>:
|
|
430
430
|
Erros personalizados:
|
431
431
|
|
432
432
|
error MeuErroPersonalizado do
|
433
|
-
'O que aconteceu foi...' + env['sinatra.error'].message
|
433
|
+
'O que aconteceu foi...' + request.env['sinatra.error'].message
|
434
434
|
end
|
435
435
|
|
436
436
|
Então, se isso acontecer:
|
data/README.rdoc
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
= Sinatra
|
2
2
|
|
3
|
-
<i>This is a backports release. If you have no reason to remain at Sinatra 1.2,
|
4
|
-
please consider upgrading.</i>
|
5
|
-
|
6
3
|
Sinatra is a DSL for quickly creating web applications in Ruby with minimal
|
7
4
|
effort:
|
8
5
|
|
@@ -37,13 +34,17 @@ Each route is associated with a block:
|
|
37
34
|
end
|
38
35
|
|
39
36
|
put '/' do
|
40
|
-
..
|
37
|
+
.. replace something ..
|
38
|
+
end
|
39
|
+
|
40
|
+
patch '/' do
|
41
|
+
.. modify something ..
|
41
42
|
end
|
42
43
|
|
43
44
|
delete '/' do
|
44
45
|
.. annihilate something ..
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
options '/' do
|
48
49
|
.. appease something ..
|
49
50
|
end
|
@@ -79,12 +80,6 @@ via the <tt>params[:splat]</tt> array:
|
|
79
80
|
params[:splat] # => ["path/to/file", "xml"]
|
80
81
|
end
|
81
82
|
|
82
|
-
Or with block parameters:
|
83
|
-
|
84
|
-
get '/download/*.*' do |path, ext|
|
85
|
-
[path, ext] # => ["path/to/file", "xml"]
|
86
|
-
end
|
87
|
-
|
88
83
|
Route matching with Regular Expressions:
|
89
84
|
|
90
85
|
get %r{/hello/([\w]+)} do
|
@@ -97,12 +92,6 @@ Or with a block parameter:
|
|
97
92
|
"Hello, #{c}!"
|
98
93
|
end
|
99
94
|
|
100
|
-
Route patterns may have optional parameters:
|
101
|
-
|
102
|
-
get '/posts.?:format?' do
|
103
|
-
# matches "GET /posts" and any extension "GET /posts.json", "GET /posts.xml" etc.
|
104
|
-
end
|
105
|
-
|
106
95
|
=== Conditions
|
107
96
|
|
108
97
|
Routes may include a variety of matching conditions, such as the user agent:
|
@@ -140,25 +129,7 @@ You can easily define your own conditions:
|
|
140
129
|
get '/win_a_car' do
|
141
130
|
"Sorry, you lost."
|
142
131
|
end
|
143
|
-
|
144
|
-
For a condition that takes multiple values use a splat:
|
145
132
|
|
146
|
-
set(:auth) do |*roles| # <- notice the splat here
|
147
|
-
condition do
|
148
|
-
unless logged_in? && roles.any? {|role| current_user.in_role? role }
|
149
|
-
redirect "/login/", 303
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
get "/my/account/", :auth => [:user, :admin] do
|
155
|
-
"Your Account Details"
|
156
|
-
end
|
157
|
-
|
158
|
-
get "/only/admin/", :auth => :admin do
|
159
|
-
"Only admins are allowed here!"
|
160
|
-
end
|
161
|
-
|
162
133
|
=== Return Values
|
163
134
|
|
164
135
|
The return value of a route block determines at least the response body passed
|
@@ -659,7 +630,7 @@ Or, specify an explicit Hash of local variables:
|
|
659
630
|
|
660
631
|
get '/:id' do
|
661
632
|
foo = Foo.find(params[:id])
|
662
|
-
haml '%h1=
|
633
|
+
haml '%h1= foo.name', :locals => { :foo => foo }
|
663
634
|
end
|
664
635
|
|
665
636
|
This is typically used when rendering templates as partials from within
|
@@ -801,20 +772,6 @@ route handlers and templates:
|
|
801
772
|
bar(params[:name])
|
802
773
|
end
|
803
774
|
|
804
|
-
Alternatively, helper methods can be separately defined in a module:
|
805
|
-
|
806
|
-
module FooUtils
|
807
|
-
def foo(name) "#{name}foo" end
|
808
|
-
end
|
809
|
-
|
810
|
-
module BarUtils
|
811
|
-
def bar(name) "#{name}bar" end
|
812
|
-
end
|
813
|
-
|
814
|
-
helpers FooUtils, BarUtils
|
815
|
-
|
816
|
-
The effect is the same as including the modules in the application class.
|
817
|
-
|
818
775
|
=== Using Sessions
|
819
776
|
|
820
777
|
A session is used to keep state during requests. If activated, you have one
|
@@ -832,9 +789,9 @@ session hash per user session:
|
|
832
789
|
|
833
790
|
Note that <tt>enable :sessions</tt> actually stores all data in a cookie. This
|
834
791
|
might not always be what you want (storing lots of data will increase your
|
835
|
-
traffic, for instance). You can use any Rack session middleware
|
792
|
+
traffic, for instance). You can use any Rack session middleware, in order to
|
836
793
|
do so, do *not* call <tt>enable :sessions</tt>, but instead pull in your
|
837
|
-
middleware of choice
|
794
|
+
middleware of choice how you would any other middleware:
|
838
795
|
|
839
796
|
use Rack::Session::Pool, :expire_after => 2592000
|
840
797
|
|
@@ -853,6 +810,11 @@ set the secret yourself, so all your application instances share it:
|
|
853
810
|
|
854
811
|
set :session_secret, 'super secret'
|
855
812
|
|
813
|
+
If you want to configure it further, you may also store a hash with options in
|
814
|
+
the +sessions+ setting:
|
815
|
+
|
816
|
+
set :sessions, :domain => 'foo.com'
|
817
|
+
|
856
818
|
=== Halting
|
857
819
|
|
858
820
|
To immediately stop a request within a filter or route use:
|
@@ -901,8 +863,8 @@ Sometimes +pass+ is not what you want, instead you would like to get the result
|
|
901
863
|
of calling another route. Simply use +call+ to achieve this:
|
902
864
|
|
903
865
|
get '/foo' do
|
904
|
-
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
905
|
-
[status,
|
866
|
+
status, headers, body = call request.env.merge("PATH_INFO" => '/bar')
|
867
|
+
[status, body.upcase]
|
906
868
|
end
|
907
869
|
|
908
870
|
get '/bar' do
|
@@ -942,7 +904,7 @@ Similar to the body, you can also set the status code and headers:
|
|
942
904
|
get '/foo' do
|
943
905
|
status 418
|
944
906
|
headers \
|
945
|
-
"Allow" => "BREW, POST, GET, PROPFIND, WHEN"
|
907
|
+
"Allow" => "BREW, POST, GET, PROPFIND, WHEN"
|
946
908
|
"Refresh" => "Refresh: 20; http://www.ietf.org/rfc/rfc2324.txt"
|
947
909
|
body "I'm a tea pot!"
|
948
910
|
end
|
@@ -950,14 +912,35 @@ Similar to the body, you can also set the status code and headers:
|
|
950
912
|
Like +body+, +headers+ and +status+ with no arguments can be used to access
|
951
913
|
their current values.
|
952
914
|
|
915
|
+
=== Logging
|
916
|
+
|
917
|
+
In the request scope, the +logger+ helper exposes a +Logger+ instance:
|
918
|
+
|
919
|
+
get '/' do
|
920
|
+
logger.info "loading data"
|
921
|
+
# ...
|
922
|
+
end
|
923
|
+
|
924
|
+
This logger will automatically take your Rack handler's logging settings into
|
925
|
+
account. If logging is disabled, this method will return a dummy object, so
|
926
|
+
you do not have to worry in your routes and filters about it.
|
927
|
+
|
928
|
+
Note that logging is only enabled for <tt>Sinatra::Application</tt> by
|
929
|
+
default, so if you inherit from <tt>Sinatra::Base</tt>, you probably want to
|
930
|
+
enable it yourself:
|
931
|
+
|
932
|
+
class MyApp < Sinatra::Base
|
933
|
+
configure(:production, :development) do
|
934
|
+
enable :logging
|
935
|
+
end
|
936
|
+
end
|
937
|
+
|
953
938
|
=== Mime Types
|
954
939
|
|
955
940
|
When using <tt>send_file</tt> or static files you may have mime types Sinatra
|
956
941
|
doesn't understand. Use +mime_type+ to register them by file extension:
|
957
942
|
|
958
|
-
|
959
|
-
mime_type :foo, 'text/foo'
|
960
|
-
end
|
943
|
+
mime_type :foo, 'text/foo'
|
961
944
|
|
962
945
|
You can also use it with the +content_type+ helper:
|
963
946
|
|
@@ -1008,7 +991,7 @@ To pass arguments with a redirect, either add them to the query:
|
|
1008
991
|
|
1009
992
|
Or use a session:
|
1010
993
|
|
1011
|
-
enable :
|
994
|
+
enable :session
|
1012
995
|
|
1013
996
|
get '/foo' do
|
1014
997
|
session[:secret] = 'foo'
|
@@ -1318,8 +1301,7 @@ You can access those options via <tt>settings</tt>:
|
|
1318
1301
|
[public] folder public files are served from
|
1319
1302
|
|
1320
1303
|
[reload_templates] whether or not to reload templates between requests.
|
1321
|
-
Enabled in development mode
|
1322
|
-
compensate a bug in Ruby causing a memory leak).
|
1304
|
+
Enabled in development mode.
|
1323
1305
|
|
1324
1306
|
[root] project root folder.
|
1325
1307
|
|
@@ -1374,7 +1356,7 @@ block or a filter. The exception object can be obtained from the
|
|
1374
1356
|
Custom errors:
|
1375
1357
|
|
1376
1358
|
error MyCustomError do
|
1377
|
-
'So what happened was...' + env['sinatra.error'].message
|
1359
|
+
'So what happened was...' + request.env['sinatra.error'].message
|
1378
1360
|
end
|
1379
1361
|
|
1380
1362
|
Then, if this happens:
|
@@ -1441,16 +1423,10 @@ debugging, URL routing, authentication, and session handling. Sinatra uses
|
|
1441
1423
|
many of these components automatically based on configuration so you
|
1442
1424
|
typically don't have to +use+ them explicitly.
|
1443
1425
|
|
1444
|
-
You can find useful middleware in
|
1445
|
-
{rack}[https://github.com/rack/rack/tree/master/lib/rack],
|
1446
|
-
{rack-contrib}[https://github.com/rack/rack-contrib#readme],
|
1447
|
-
with {CodeRack}[http://coderack.org/] or in the
|
1448
|
-
{Rack wiki}[https://github.com/rack/rack/wiki/List-of-Middleware].
|
1449
|
-
|
1450
1426
|
== Testing
|
1451
1427
|
|
1452
1428
|
Sinatra tests can be written using any Rack-based testing library
|
1453
|
-
or framework. {Rack::Test}[http://
|
1429
|
+
or framework. {Rack::Test}[http://gitrdoc.com/brynary/rack-test] is
|
1454
1430
|
recommended:
|
1455
1431
|
|
1456
1432
|
require 'my_sinatra_app'
|
@@ -1480,6 +1456,9 @@ recommended:
|
|
1480
1456
|
end
|
1481
1457
|
end
|
1482
1458
|
|
1459
|
+
NOTE: The built-in Sinatra::Test module and Sinatra::TestHarness class
|
1460
|
+
are deprecated as of the 0.9.2 release.
|
1461
|
+
|
1483
1462
|
== Sinatra::Base - Middleware, Libraries, and Modular Apps
|
1484
1463
|
|
1485
1464
|
Defining your app at the top-level works well for micro-apps but has
|
@@ -1487,8 +1466,8 @@ considerable drawbacks when building reusable components such as Rack
|
|
1487
1466
|
middleware, Rails metal, simple libraries with a server component, or
|
1488
1467
|
even Sinatra extensions. The top-level DSL pollutes the Object namespace
|
1489
1468
|
and assumes a micro-app style configuration (e.g., a single application
|
1490
|
-
file,
|
1491
|
-
|
1469
|
+
file, ./public and ./views directories, logging, exception detail page,
|
1470
|
+
etc.). That's where Sinatra::Base comes into play:
|
1492
1471
|
|
1493
1472
|
require 'sinatra/base'
|
1494
1473
|
|
@@ -1501,15 +1480,15 @@ detail page, etc.). That's where <tt>Sinatra::Base</tt> comes into play:
|
|
1501
1480
|
end
|
1502
1481
|
end
|
1503
1482
|
|
1504
|
-
The methods available to
|
1483
|
+
The methods available to Sinatra::Base subclasses are exactly as those
|
1505
1484
|
available via the top-level DSL. Most top-level apps can be converted to
|
1506
|
-
|
1485
|
+
Sinatra::Base components with two modifications:
|
1507
1486
|
|
1508
1487
|
* Your file should require <tt>sinatra/base</tt> instead of +sinatra+;
|
1509
1488
|
otherwise, all of Sinatra's DSL methods are imported into the main
|
1510
1489
|
namespace.
|
1511
1490
|
* Put your app's routes, error handlers, filters, and options in a subclass
|
1512
|
-
of
|
1491
|
+
of Sinatra::Base.
|
1513
1492
|
|
1514
1493
|
<tt>Sinatra::Base</tt> is a blank slate. Most options are disabled by default,
|
1515
1494
|
including the built-in server. See {Options and Configuration}[http://sinatra.github.com/configuration.html]
|
@@ -1530,8 +1509,8 @@ There are only two downsides compared with modular style:
|
|
1530
1509
|
|
1531
1510
|
There is no reason you cannot mix modular and classic style.
|
1532
1511
|
|
1533
|
-
If switching from one style to the other, you should be aware of
|
1534
|
-
|
1512
|
+
If switching from one style to the other, you should be aware of slight
|
1513
|
+
differences in the setting:
|
1535
1514
|
|
1536
1515
|
Setting Classic Modular
|
1537
1516
|
|
@@ -1564,7 +1543,7 @@ Start with:
|
|
1564
1543
|
Or with a <tt>config.ru</tt>, which allows using any Rack handler:
|
1565
1544
|
|
1566
1545
|
# config.ru
|
1567
|
-
require '
|
1546
|
+
require 'my_app'
|
1568
1547
|
run MyApp
|
1569
1548
|
|
1570
1549
|
Run:
|
@@ -1584,7 +1563,7 @@ Write your app file:
|
|
1584
1563
|
|
1585
1564
|
And a corresponding <tt>config.ru</tt>:
|
1586
1565
|
|
1587
|
-
require '
|
1566
|
+
require 'app'
|
1588
1567
|
run Sinatra::Application
|
1589
1568
|
|
1590
1569
|
=== When to use a config.ru?
|
@@ -1615,7 +1594,7 @@ application (Rails/Ramaze/Camping/...):
|
|
1615
1594
|
get('/login') { haml :login }
|
1616
1595
|
|
1617
1596
|
post('/login') do
|
1618
|
-
if params[:name]
|
1597
|
+
if params[:name] = 'admin' and params[:password] = 'admin'
|
1619
1598
|
session['user_name'] = params[:name]
|
1620
1599
|
else
|
1621
1600
|
redirect '/login'
|
@@ -1636,46 +1615,6 @@ application (Rails/Ramaze/Camping/...):
|
|
1636
1615
|
get('/') { "Hello #{session['user_name']}." }
|
1637
1616
|
end
|
1638
1617
|
|
1639
|
-
=== Dynamic Application Creation
|
1640
|
-
|
1641
|
-
Sometimes you want to create new applications at runtime without having to
|
1642
|
-
assign them to a constant, you can do this with <tt>Sinatra.new</tt>:
|
1643
|
-
|
1644
|
-
require 'sinatra/base'
|
1645
|
-
my_app = Sinatra.new { get('/') { "hi" } }
|
1646
|
-
my_app.run!
|
1647
|
-
|
1648
|
-
It takes the application to inherit from as optional argument:
|
1649
|
-
|
1650
|
-
# config.ru
|
1651
|
-
require 'sinatra/base'
|
1652
|
-
|
1653
|
-
controller = Sinatra.new do
|
1654
|
-
enable :logging
|
1655
|
-
helpers MyHelpers
|
1656
|
-
end
|
1657
|
-
|
1658
|
-
map('/a') do
|
1659
|
-
run Sinatra.new(controller) { get('/') { 'a' } }
|
1660
|
-
end
|
1661
|
-
|
1662
|
-
map('/b') do
|
1663
|
-
run Sinatra.new(controller) { get('/') { 'b' } }
|
1664
|
-
end
|
1665
|
-
|
1666
|
-
This is especially useful for testing Sinatra extensions or using Sinatra in
|
1667
|
-
your own library.
|
1668
|
-
|
1669
|
-
This also makes using Sinatra as middleware extremely easy:
|
1670
|
-
|
1671
|
-
require 'sinatra/base'
|
1672
|
-
|
1673
|
-
use Sinatra do
|
1674
|
-
get('/') { ... }
|
1675
|
-
end
|
1676
|
-
|
1677
|
-
run RailsProject::Application
|
1678
|
-
|
1679
1618
|
== Scopes and Binding
|
1680
1619
|
|
1681
1620
|
The scope you are currently in determines what methods and variables are
|
@@ -1683,9 +1622,9 @@ available.
|
|
1683
1622
|
|
1684
1623
|
=== Application/Class Scope
|
1685
1624
|
|
1686
|
-
Every Sinatra application corresponds to a subclass of
|
1625
|
+
Every Sinatra application corresponds to a subclass of Sinatra::Base. If you
|
1687
1626
|
are using the top-level DSL (<tt>require 'sinatra'</tt>), then this class is
|
1688
|
-
|
1627
|
+
Sinatra::Application, otherwise it is the subclass you created explicitly. At
|
1689
1628
|
class level you have methods like +get+ or +before+, but you cannot access the
|
1690
1629
|
+request+ object or the +session+, as there only is a single application class
|
1691
1630
|
for all requests.
|
@@ -1708,7 +1647,6 @@ You have the application scope binding inside:
|
|
1708
1647
|
* Methods defined by extensions
|
1709
1648
|
* The block passed to +helpers+
|
1710
1649
|
* Procs/blocks used as value for +set+
|
1711
|
-
* The block passed to <tt>Sinatra.new</tt>
|
1712
1650
|
|
1713
1651
|
You can reach the scope object (the class) like this:
|
1714
1652
|
|
@@ -1778,21 +1716,10 @@ Options are:
|
|
1778
1716
|
-s # specify rack server/handler (default is thin)
|
1779
1717
|
-x # turn on the mutex lock (default is off)
|
1780
1718
|
|
1781
|
-
==
|
1782
|
-
|
1783
|
-
It is recommended to install Sinatra on Ruby 1.8.7, 1.9.2, JRuby or Rubinius.
|
1719
|
+
== Requirement
|
1784
1720
|
|
1785
1721
|
The following Ruby versions are officially supported:
|
1786
1722
|
|
1787
|
-
[ Ruby 1.8.6 ]
|
1788
|
-
It is not recommended to use 1.8.6 for Sinatra. However, it is still supported
|
1789
|
-
in Sinatra 1.2 (this version), it has been dropped in Sinatra 1.3.0, though.
|
1790
|
-
RDoc and CoffeeScript templates are not supported. 1.8.6 includes a major
|
1791
|
-
memory leak in its Hash implementation, which is triggered by Sinatra versions
|
1792
|
-
prior to 1.1.1. The current version explicitly prevents this leak at the cost
|
1793
|
-
of performance. You will have to downgrade Rack to 1.1.x, as Rack >= 1.2 no
|
1794
|
-
longer supports 1.8.6.
|
1795
|
-
|
1796
1723
|
[ Ruby 1.8.7 ]
|
1797
1724
|
1.8.7 is fully supported, however, if nothing is keeping you from it, we
|
1798
1725
|
recommend upgrading to 1.9.2 or switching to JRuby or Rubinius.
|
@@ -1813,6 +1740,8 @@ The following Ruby versions are officially supported:
|
|
1813
1740
|
on JRuby. JRuby's support for C extensions is still experimental, which only
|
1814
1741
|
affects RDiscount at the moment.
|
1815
1742
|
|
1743
|
+
<b>Ruby 1.8.6 is no longer supported.</b>
|
1744
|
+
|
1816
1745
|
We also keep an eye on upcoming Ruby versions.
|
1817
1746
|
|
1818
1747
|
The following Ruby implementations are not officially supported but still are
|
@@ -1821,6 +1750,7 @@ known to run Sinatra:
|
|
1821
1750
|
* Older versions of JRuby and Rubinius
|
1822
1751
|
* MacRuby, Maglev, IronRuby
|
1823
1752
|
* Ruby 1.9.0 and 1.9.1
|
1753
|
+
* Ruby 1.8.6 with {backports}[https://github.com/marcandre/backports/#readme]
|
1824
1754
|
|
1825
1755
|
Not being officially supported means if things only break there and not on a
|
1826
1756
|
supported platform, we assume it's not our issue but theirs.
|
@@ -1908,9 +1838,4 @@ SemVerTag.
|
|
1908
1838
|
* {Twitter}[http://twitter.com/sinatra]
|
1909
1839
|
* {Mailing List}[http://groups.google.com/group/sinatrarb/topics]
|
1910
1840
|
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] on http://freenode.net
|
1911
|
-
* {Sinatra Book}[http://sinatra-book.gittr.com] Cookbook Tutorial
|
1912
|
-
* {Sinatra Book Contrib}[http://sinatra-book-contrib.com/] Community contributed recipes
|
1913
|
-
* API documentation for the {latest release}[http://rubydoc.info/gems/sinatra]
|
1914
|
-
or the {current HEAD}[http://rubydoc.info/github/sinatra/sinatra] on
|
1915
|
-
http://rubydoc.info/
|
1916
1841
|
|