sinatra 1.2.6 → 1.2.7

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.

data/CHANGES CHANGED
@@ -1,3 +1,36 @@
1
+ = 1.2.7 (backports release) / Not Yet Released
2
+
3
+ Custom changes:
4
+
5
+ * Fix Ruby 1.8.6 issue with Accept header parsing. (Konstantin Haase)
6
+
7
+ Backported from 1.3.0:
8
+
9
+ * Ignore `to_ary` on response bodies. Fixes compatibility to Rails 3.1.
10
+ (Konstantin Haase)
11
+
12
+ * `Sinatra.run!` now prints to stderr rather than stdout. (Andrew Armenia)
13
+
14
+ * Automatic `app_file` detection now works in directories containing brackets
15
+ (Konstantin Haase)
16
+
17
+ * Improved documentation. (Emanuele Vicentini, Peter Higgins, Takanori
18
+ Ishikawa, Konstantin Haase)
19
+
20
+ * Also specify charset in Content-Type header for JSON. (Konstantin Haase)
21
+
22
+ * Rack handler names will not be converted to lower case internally, this
23
+ allows you to run Sinatra with custom Rack handlers, like Kirk or Mongrel2.
24
+ Example: `ruby app.rb -s Mongrel2` (Konstantin Haase)
25
+
26
+ * Fix uninitialized instance variable warning. (David Kellum)
27
+
28
+ * Command line options now complain if value passed to `-p` is not a valid
29
+ integer. (Konstantin Haase)
30
+
31
+ * Fix handling of broken query params when displaying exceptions. (Luke
32
+ Jahnke)
33
+
1
34
  = 1.2.6 / 2011-05-01
2
35
 
3
36
  * Fix broken delegation, backport delegation tests from Sinatra 1.3.
@@ -130,7 +163,7 @@
130
163
  * Sinatra now ships with a Gemfile for development dependencies, since it eases
131
164
  supporting different platforms, like JRuby. (Konstantin Haase)
132
165
 
133
- = 1.1.4 / 2011-04-13
166
+ = 1.1.4 (backports release) / 2011-04-13
134
167
 
135
168
  * Compatible with Tilt 1.3. (Konstantin Haase)
136
169
 
data/Gemfile CHANGED
@@ -7,38 +7,40 @@
7
7
  # If you have issues with a gem: `bundle install --without-coffee-script`.
8
8
 
9
9
  RUBY_ENGINE = 'ruby' unless defined? RUBY_ENGINE
10
- TILT_REPO = "git://github.com/rtomayko/tilt.git"
11
-
12
10
  source :rubygems unless ENV['QUICK']
13
- gemspec
14
11
 
15
- gem 'rake'
12
+ gem 'rake', '~> 0.8.7'
16
13
  gem 'rack-test', '>= 0.5.6'
14
+ gem 'ci_reporter', :group => :ci
17
15
 
18
16
  # Allows stuff like `tilt=1.2.2 bundle install` or `tilt=master ...`.
19
17
  # Used by the CI.
20
- tilt = (ENV['tilt'] || 'stable').dup
21
- tilt.sub! 'tilt-', ''
22
- if tilt != 'stable'
23
- tilt = {:git => TILT_REPO, :branch => tilt} unless tilt =~ /(\d+\.)+\d+/
24
- gem 'tilt', tilt
18
+ github = "git://github.com/%s.git"
19
+ repos = { 'tilt' => github % "rtomayko/tilt", 'rack' => github % "rack/rack" }
20
+ %w[tilt rack].each do |lib|
21
+ dep = (ENV[lib] || 'stable').sub "#{lib}-", ''
22
+ dep = nil if dep == 'stable'
23
+ dep = {:git => repos[lib], :branch => dep} if dep and dep !~ /(\d+\.)+\d+/
24
+ dep ||= '~> 1.1.0' if lib == 'rack' and RUBY_VERSION == '1.8.6'
25
+ gem lib, dep
25
26
  end
26
27
 
27
- gem 'haml', '>= 3.0', :group => 'haml'
28
+ gem 'haml', '~> 3.0.0', :group => 'haml'
28
29
  gem 'builder', :group => 'builder'
29
30
  gem 'erubis', :group => 'erubis'
30
- gem 'less', :group => 'less'
31
+ gem 'less', '~> 1.0', :group => 'less'
31
32
  gem 'liquid', :group => 'liquid'
32
- gem 'nokogiri', :group => 'nokogiri'
33
33
  gem 'slim', :group => 'slim'
34
- gem 'RedCloth', :group => 'redcloth'
35
-
34
+ gem 'RedCloth', :group => 'redcloth' if RUBY_VERSION < "1.9.3" and RUBY_ENGINE != 'macruby'
36
35
 
37
36
  if RUBY_VERSION > '1.8.6'
37
+ if RUBY_ENGINE == 'jruby'
38
+ gem 'nokogiri', '!= 1.5.0'
39
+ elsif RUBY_ENGINE != 'maglev'
40
+ gem 'nokogiri'
41
+ end
38
42
  gem 'coffee-script', '>= 2.0', :group => 'coffee-script'
39
43
  gem 'rdoc', :group => 'rdoc'
40
- else
41
- gem 'rack', '~> 1.1.0'
42
44
  end
43
45
 
44
46
  platforms :ruby do
@@ -947,7 +947,7 @@ Vergleichbar mit +body+ lassen sich auch Status-Code und Header setzen:
947
947
  get '/foo' do
948
948
  status 418
949
949
  headers \
950
- "Allow" => "BREW, POST, GET, PROPFIND, WHEN"
950
+ "Allow" => "BREW, POST, GET, PROPFIND, WHEN",
951
951
  "Refresh" => "Refresh: 20; http://www.ietf.org/rfc/rfc2324.txt"
952
952
  halt "Ich bin ein Teekesselchen"
953
953
  end
@@ -1018,7 +1018,7 @@ Um Argumente an ein Redirect weiterzugeben, können sie entweder dem Query
1018
1018
 
1019
1019
  oder eine Session verwendet werden:
1020
1020
 
1021
- enable :session
1021
+ enable :sessions
1022
1022
 
1023
1023
  get '/foo' do
1024
1024
  session[:secret] = 'foo'
@@ -1561,7 +1561,7 @@ Oder über eine <tt>config.ru</tt>-Datei, die es erlaubt, einen beliebigen
1561
1561
  Rack-Handler zu verwenden:
1562
1562
 
1563
1563
  # config.ru
1564
- require 'mein_app'
1564
+ require './mein_app'
1565
1565
  run MeineApp
1566
1566
 
1567
1567
  Starte:
@@ -1582,7 +1582,7 @@ Schreibe eine Anwendungsdatei:
1582
1582
 
1583
1583
  sowie eine dazugehörige <tt>config.ru</tt>-Datei:
1584
1584
 
1585
- require 'app'
1585
+ require './app'
1586
1586
  run Sinatra::Application
1587
1587
 
1588
1588
 
@@ -916,7 +916,7 @@ De manera similar, también podés asignar el código de estado y encabezados:
916
916
  get '/foo' do
917
917
  status 418
918
918
  headers \
919
- "Allow" => "BREW, POST, GET, PROPFIND, WHEN"
919
+ "Allow" => "BREW, POST, GET, PROPFIND, WHEN",
920
920
  "Refresh" => "Refresh: 20; http://www.ietf.org/rfc/rfc2324.txt"
921
921
  body "I'm a tea pot!"
922
922
  end
@@ -983,7 +983,7 @@ búsqueda:
983
983
 
984
984
  O usar una sesión:
985
985
 
986
- enable :session
986
+ enable :sessions
987
987
 
988
988
  get '/foo' do
989
989
  session[:secreto] = 'foo'
@@ -1560,7 +1560,7 @@ Iniciar con:
1560
1560
  O, con un archivo <tt>config.ru</tt>, que permite usar cualquier handler Rack:
1561
1561
 
1562
1562
  # config.ru
1563
- require 'mi_app'
1563
+ require './mi_app'
1564
1564
  run MiApp
1565
1565
 
1566
1566
  Después ejecutar:
@@ -1580,7 +1580,7 @@ Escribí el archivo de tu aplicación:
1580
1580
 
1581
1581
  Y el <tt>config.ru</tt> correspondiente:
1582
1582
 
1583
- require 'app'
1583
+ require './app'
1584
1584
  run Sinatra::Application
1585
1585
 
1586
1586
  === ¿Cuándo Usar config.ru?
@@ -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 :session
1011
+ enable :sessions
1012
1012
 
1013
1013
  get '/foo' do
1014
1014
  session[:secret] = 'foo'
@@ -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 'my_app'
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 'app'
1618
+ require './app'
1619
1619
  run Sinatra::Application
1620
1620
 
1621
1621
  === Quand utiliser un fichier config.ru ?
@@ -67,6 +67,12 @@ 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
+
70
76
  正規表現を使ったルート:
71
77
 
72
78
  get %r{/hello/([\w]+)} do
@@ -990,7 +996,7 @@ Sinatraの開発版を使いたい場合は、ローカルに開発版を落と
990
996
  git clone git://github.com/sinatra/sinatra.git
991
997
  ruby -Isinatra/lib myapp.rb
992
998
 
993
- <tt>sinatra/lib</tt>ディレクトリをto the<tt>LOAD_PATH</tt>に追加する方法もあります。
999
+ <tt>sinatra/lib</tt>ディレクトリをアプリケーションの<tt>LOAD_PATH</tt>に追加する方法もあります。
994
1000
 
995
1001
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/sinatra/lib'
996
1002
  require 'rubygems'
@@ -1,5 +1,8 @@
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
+
3
6
  Sinatra is a DSL for quickly creating web applications in Ruby with minimal
4
7
  effort:
5
8
 
@@ -76,6 +79,12 @@ via the <tt>params[:splat]</tt> array:
76
79
  params[:splat] # => ["path/to/file", "xml"]
77
80
  end
78
81
 
82
+ Or with block parameters:
83
+
84
+ get '/download/*.*' do |path, ext|
85
+ [path, ext] # => ["path/to/file", "xml"]
86
+ end
87
+
79
88
  Route matching with Regular Expressions:
80
89
 
81
90
  get %r{/hello/([\w]+)} do
@@ -88,6 +97,12 @@ Or with a block parameter:
88
97
  "Hello, #{c}!"
89
98
  end
90
99
 
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
+
91
106
  === Conditions
92
107
 
93
108
  Routes may include a variety of matching conditions, such as the user agent:
@@ -125,7 +140,25 @@ You can easily define your own conditions:
125
140
  get '/win_a_car' do
126
141
  "Sorry, you lost."
127
142
  end
143
+
144
+ For a condition that takes multiple values use a splat:
145
+
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
128
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
+
129
162
  === Return Values
130
163
 
131
164
  The return value of a route block determines at least the response body passed
@@ -626,7 +659,7 @@ Or, specify an explicit Hash of local variables:
626
659
 
627
660
  get '/:id' do
628
661
  foo = Foo.find(params[:id])
629
- haml '%h1= foo.name', :locals => { :foo => foo }
662
+ haml '%h1= bar.name', :locals => { :bar => foo }
630
663
  end
631
664
 
632
665
  This is typically used when rendering templates as partials from within
@@ -785,9 +818,9 @@ session hash per user session:
785
818
 
786
819
  Note that <tt>enable :sessions</tt> actually stores all data in a cookie. This
787
820
  might not always be what you want (storing lots of data will increase your
788
- traffic, for instance). You can use any Rack session middleware, in order to
821
+ traffic, for instance). You can use any Rack session middleware: in order to
789
822
  do so, do *not* call <tt>enable :sessions</tt>, but instead pull in your
790
- middleware of choice how you would any other middleware:
823
+ middleware of choice as you would any other middleware:
791
824
 
792
825
  use Rack::Session::Pool, :expire_after => 2592000
793
826
 
@@ -895,7 +928,7 @@ Similar to the body, you can also set the status code and headers:
895
928
  get '/foo' do
896
929
  status 418
897
930
  headers \
898
- "Allow" => "BREW, POST, GET, PROPFIND, WHEN"
931
+ "Allow" => "BREW, POST, GET, PROPFIND, WHEN",
899
932
  "Refresh" => "Refresh: 20; http://www.ietf.org/rfc/rfc2324.txt"
900
933
  body "I'm a tea pot!"
901
934
  end
@@ -908,7 +941,9 @@ their current values.
908
941
  When using <tt>send_file</tt> or static files you may have mime types Sinatra
909
942
  doesn't understand. Use +mime_type+ to register them by file extension:
910
943
 
911
- mime_type :foo, 'text/foo'
944
+ configure do
945
+ mime_type :foo, 'text/foo'
946
+ end
912
947
 
913
948
  You can also use it with the +content_type+ helper:
914
949
 
@@ -959,7 +994,7 @@ To pass arguments with a redirect, either add them to the query:
959
994
 
960
995
  Or use a session:
961
996
 
962
- enable :session
997
+ enable :sessions
963
998
 
964
999
  get '/foo' do
965
1000
  session[:secret] = 'foo'
@@ -1392,10 +1427,16 @@ debugging, URL routing, authentication, and session handling. Sinatra uses
1392
1427
  many of these components automatically based on configuration so you
1393
1428
  typically don't have to +use+ them explicitly.
1394
1429
 
1430
+ You can find useful middleware in
1431
+ {rack}[https://github.com/rack/rack/tree/master/lib/rack],
1432
+ {rack-contrib}[https://github.com/rack/rack-contrib#readme],
1433
+ with {CodeRack}[http://coderack.org/] or in the
1434
+ {Rack wiki}[https://github.com/rack/rack/wiki/List-of-Middleware].
1435
+
1395
1436
  == Testing
1396
1437
 
1397
1438
  Sinatra tests can be written using any Rack-based testing library
1398
- or framework. {Rack::Test}[http://gitrdoc.com/brynary/rack-test] is
1439
+ or framework. {Rack::Test}[http://rdoc.info/github/brynary/rack-test/master/frames] is
1399
1440
  recommended:
1400
1441
 
1401
1442
  require 'my_sinatra_app'
@@ -1425,9 +1466,6 @@ recommended:
1425
1466
  end
1426
1467
  end
1427
1468
 
1428
- NOTE: The built-in Sinatra::Test module and Sinatra::TestHarness class
1429
- are deprecated as of the 0.9.2 release.
1430
-
1431
1469
  == Sinatra::Base - Middleware, Libraries, and Modular Apps
1432
1470
 
1433
1471
  Defining your app at the top-level works well for micro-apps but has
@@ -1435,8 +1473,8 @@ considerable drawbacks when building reusable components such as Rack
1435
1473
  middleware, Rails metal, simple libraries with a server component, or
1436
1474
  even Sinatra extensions. The top-level DSL pollutes the Object namespace
1437
1475
  and assumes a micro-app style configuration (e.g., a single application
1438
- file, ./public and ./views directories, logging, exception detail page,
1439
- etc.). That's where Sinatra::Base comes into play:
1476
+ file, <tt>./public</tt> and <tt>./views</tt> directories, logging, exception
1477
+ detail page, etc.). That's where <tt>Sinatra::Base</tt> comes into play:
1440
1478
 
1441
1479
  require 'sinatra/base'
1442
1480
 
@@ -1449,15 +1487,15 @@ etc.). That's where Sinatra::Base comes into play:
1449
1487
  end
1450
1488
  end
1451
1489
 
1452
- The methods available to Sinatra::Base subclasses are exactly as those
1490
+ The methods available to <tt>Sinatra::Base</tt> subclasses are exactly as those
1453
1491
  available via the top-level DSL. Most top-level apps can be converted to
1454
- Sinatra::Base components with two modifications:
1492
+ <tt>Sinatra::Base</tt> components with two modifications:
1455
1493
 
1456
1494
  * Your file should require <tt>sinatra/base</tt> instead of +sinatra+;
1457
1495
  otherwise, all of Sinatra's DSL methods are imported into the main
1458
1496
  namespace.
1459
1497
  * Put your app's routes, error handlers, filters, and options in a subclass
1460
- of Sinatra::Base.
1498
+ of <tt>Sinatra::Base</tt>.
1461
1499
 
1462
1500
  <tt>Sinatra::Base</tt> is a blank slate. Most options are disabled by default,
1463
1501
  including the built-in server. See {Options and Configuration}[http://sinatra.github.com/configuration.html]
@@ -1512,7 +1550,7 @@ Start with:
1512
1550
  Or with a <tt>config.ru</tt>, which allows using any Rack handler:
1513
1551
 
1514
1552
  # config.ru
1515
- require 'my_app'
1553
+ require './my_app'
1516
1554
  run MyApp
1517
1555
 
1518
1556
  Run:
@@ -1532,7 +1570,7 @@ Write your app file:
1532
1570
 
1533
1571
  And a corresponding <tt>config.ru</tt>:
1534
1572
 
1535
- require 'app'
1573
+ require './app'
1536
1574
  run Sinatra::Application
1537
1575
 
1538
1576
  === When to use a config.ru?
@@ -1563,7 +1601,7 @@ application (Rails/Ramaze/Camping/...):
1563
1601
  get('/login') { haml :login }
1564
1602
 
1565
1603
  post('/login') do
1566
- if params[:name] = 'admin' and params[:password] = 'admin'
1604
+ if params[:name] == 'admin' && params[:password] == 'admin'
1567
1605
  session['user_name'] = params[:name]
1568
1606
  else
1569
1607
  redirect '/login'
@@ -1595,6 +1633,7 @@ assign them to a constant, you can do this with <tt>Sinatra.new</tt>:
1595
1633
 
1596
1634
  It takes the application to inherit from as optional argument:
1597
1635
 
1636
+ # config.ru
1598
1637
  require 'sinatra/base'
1599
1638
 
1600
1639
  controller = Sinatra.new do
@@ -1630,9 +1669,9 @@ available.
1630
1669
 
1631
1670
  === Application/Class Scope
1632
1671
 
1633
- Every Sinatra application corresponds to a subclass of Sinatra::Base. If you
1672
+ Every Sinatra application corresponds to a subclass of <tt>Sinatra::Base</tt>. If you
1634
1673
  are using the top-level DSL (<tt>require 'sinatra'</tt>), then this class is
1635
- Sinatra::Application, otherwise it is the subclass you created explicitly. At
1674
+ <tt>Sinatra::Application</tt>, otherwise it is the subclass you created explicitly. At
1636
1675
  class level you have methods like +get+ or +before+, but you cannot access the
1637
1676
  +request+ object or the +session+, as there only is a single application class
1638
1677
  for all requests.
@@ -1732,13 +1771,13 @@ It is recommended to install Sinatra on Ruby 1.8.7, 1.9.2, JRuby or Rubinius.
1732
1771
  The following Ruby versions are officially supported:
1733
1772
 
1734
1773
  [ Ruby 1.8.6 ]
1735
- It is not recommended to use 1.8.6 for Sinatra. However, it will be
1736
- officially supported until Sinatra 1.3.0 is released. RDoc and CoffeeScript
1737
- templates are not supported by this Ruby version. 1.8.6 includes a major
1738
- memory leak in its Hash implementation, which is triggered by Sinatra
1739
- versions prior to 1.1.1. The current version explicitly prevents this leak
1740
- at the cost of performance. You will have to downgrade Rack to 1.1.x, as
1741
- Rack >= 1.2 no longer supports 1.8.6.
1774
+ It is not recommended to use 1.8.6 for Sinatra. However, it is still supported
1775
+ in Sinatra 1.2 (this version), it has been dropped in Sinatra 1.3.0, though.
1776
+ RDoc and CoffeeScript templates are not supported. 1.8.6 includes a major
1777
+ memory leak in its Hash implementation, which is triggered by Sinatra versions
1778
+ prior to 1.1.1. The current version explicitly prevents this leak at the cost
1779
+ of performance. You will have to downgrade Rack to 1.1.x, as Rack >= 1.2 no
1780
+ longer supports 1.8.6.
1742
1781
 
1743
1782
  [ Ruby 1.8.7 ]
1744
1783
  1.8.7 is fully supported, however, if nothing is keeping you from it, we