sinatra 0.9.2 → 0.9.4
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 +18 -1
- data/README.rdoc +51 -1
- data/lib/sinatra/base.rb +7 -6
- data/sinatra.gemspec +3 -2
- data/test/options_test.rb +7 -2
- data/test/server_test.rb +14 -10
- data/test/templates_test.rb +22 -0
- data/test/views/foo/hello.test +1 -0
- metadata +6 -3
data/CHANGES
CHANGED
@@ -1,4 +1,21 @@
|
|
1
|
-
= 0.9.
|
1
|
+
= 0.9.4 / 2009-07-26
|
2
|
+
|
3
|
+
* The app_file and run options should be properly detected
|
4
|
+
on Debian when installed from apt package.
|
5
|
+
|
6
|
+
* The :show_exceptions option now defaults to false in all
|
7
|
+
cases for subclasses of Sinatra::Base.
|
8
|
+
|
9
|
+
* Fix webrick server handler not found errors when starting
|
10
|
+
from the command line without mongrel or thin [#231].
|
11
|
+
|
12
|
+
* Fix locals not being passed to layouts.
|
13
|
+
|
14
|
+
* Fix 'Illegal Seek' errors running under Apache/CGI.
|
15
|
+
|
16
|
+
= 0.9.3 / unreleased
|
17
|
+
|
18
|
+
= 0.9.2 / 2009-05-18
|
2
19
|
|
3
20
|
* This version is compatible with Rack 1.0. [Rein Henrichs]
|
4
21
|
|
data/README.rdoc
CHANGED
@@ -45,7 +45,7 @@ Route patterns may include named parameters, accessible via the
|
|
45
45
|
<tt>params</tt> hash:
|
46
46
|
|
47
47
|
get '/hello/:name' do
|
48
|
-
# matches "GET /foo" and "GET /bar"
|
48
|
+
# matches "GET /hello/foo" and "GET /hello/bar"
|
49
49
|
# params[:name] is 'foo' or 'bar'
|
50
50
|
"Hello #{params[:name]}!"
|
51
51
|
end
|
@@ -470,6 +470,56 @@ recommended:
|
|
470
470
|
NOTE: The built-in Sinatra::Test module and Sinatra::TestHarness class
|
471
471
|
are deprecated as of the 0.9.2 release.
|
472
472
|
|
473
|
+
== Sinatra::Base - Middleware, Libraries, and Modular Apps
|
474
|
+
|
475
|
+
Defining your app at the top-level works well for micro-apps but has
|
476
|
+
considerable drawbacks when building reuseable components such as Rack
|
477
|
+
middleware, Rails metal, simple libraries with a server component, or
|
478
|
+
even Sinatra extensions. The top-level DSL pollutes the Object namespace
|
479
|
+
and assumes a micro-app style configuration (e.g., a single application
|
480
|
+
file, ./public and ./views directories, logging, exception detail page,
|
481
|
+
etc.). That's where Sinatra::Base comes into play:
|
482
|
+
|
483
|
+
require 'sinatra/base'
|
484
|
+
|
485
|
+
class MyApp < Sinatra::Base
|
486
|
+
set :sessions, true
|
487
|
+
set :foo, 'bar'
|
488
|
+
|
489
|
+
get '/' do
|
490
|
+
'Hello world!'
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
The MyApp class is an independent Rack component that can act as
|
495
|
+
Rack middleware, a Rack application, or Rails metal. You can +use+ or
|
496
|
+
+run+ this class from a rackup +config.ru+ file; or, control a server
|
497
|
+
component shipped as a library:
|
498
|
+
|
499
|
+
MyApp.run! :host => 'localhost', :port => 9090
|
500
|
+
|
501
|
+
The methods available to Sinatra::Base subclasses are exactly as those
|
502
|
+
available via the top-level DSL. Most top-level apps can be converted to
|
503
|
+
Sinatra::Base components with two modifications:
|
504
|
+
|
505
|
+
* Your file should require +sinatra/base+ instead of +sinatra+;
|
506
|
+
otherwise, all of Sinatra's DSL methods are imported into the main
|
507
|
+
namespace.
|
508
|
+
* Put your app's routes, error handlers, filters, and options in a subclass
|
509
|
+
of Sinatra::Base.
|
510
|
+
|
511
|
+
+Sinatra::Base+ is a blank slate. Most options are disabled by default,
|
512
|
+
including the built-in server. See {Options and Configuration}[http://sinatra.github.com/configuration.html]
|
513
|
+
for details on available options and their behavior.
|
514
|
+
|
515
|
+
SIDEBAR: Sinatra's top-level DSL is implemented using a simple delegation
|
516
|
+
system. The +Sinatra::Application+ class -- a special subclass of
|
517
|
+
Sinatra::Base -- receives all :get, :put, :post, :delete, :before,
|
518
|
+
:error, :not_found, :configure, and :set messages sent to the
|
519
|
+
top-level. Have a look at the code for yourself: here's the
|
520
|
+
{Sinatra::Delegator mixin}[http://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1064]
|
521
|
+
being {included into the main namespace}[http://github.com/sinatra/sinatra/blob/master/lib/sinatra/main.rb#L25].
|
522
|
+
|
473
523
|
== Command line
|
474
524
|
|
475
525
|
Sinatra applications can be run directly:
|
data/lib/sinatra/base.rb
CHANGED
@@ -6,7 +6,7 @@ require 'rack/builder'
|
|
6
6
|
require 'sinatra/showexceptions'
|
7
7
|
|
8
8
|
module Sinatra
|
9
|
-
VERSION = '0.9.
|
9
|
+
VERSION = '0.9.4'
|
10
10
|
|
11
11
|
# The request object. See Rack::Request for more info:
|
12
12
|
# http://rack.rubyforge.org/doc/classes/Rack/Request.html
|
@@ -23,7 +23,7 @@ module Sinatra
|
|
23
23
|
# Override Rack 0.9.x's #params implementation (see #72 in lighthouse)
|
24
24
|
def params
|
25
25
|
self.GET.update(self.POST)
|
26
|
-
rescue EOFError
|
26
|
+
rescue EOFError, Errno::ESPIPE
|
27
27
|
self.GET
|
28
28
|
end
|
29
29
|
end
|
@@ -268,7 +268,7 @@ module Sinatra
|
|
268
268
|
if layout
|
269
269
|
data, options[:filename], options[:line] = lookup_layout(engine, layout, views)
|
270
270
|
if data
|
271
|
-
output = __send__("render_#{engine}", layout, data, options,
|
271
|
+
output = __send__("render_#{engine}", layout, data, options, locals) { output }
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
@@ -922,7 +922,7 @@ module Sinatra
|
|
922
922
|
servers = Array(self.server)
|
923
923
|
servers.each do |server_name|
|
924
924
|
begin
|
925
|
-
return Rack::Handler.get(server_name.
|
925
|
+
return Rack::Handler.get(server_name.downcase)
|
926
926
|
rescue LoadError
|
927
927
|
rescue NameError
|
928
928
|
end
|
@@ -951,7 +951,7 @@ module Sinatra
|
|
951
951
|
|
952
952
|
public
|
953
953
|
CALLERS_TO_IGNORE = [
|
954
|
-
|
954
|
+
/\/sinatra(\/(base|main|showexceptions|compat))?\.rb$/, # all sinatra code
|
955
955
|
/\(.*\)/, # generated code
|
956
956
|
/custom_require\.rb$/, # rubygems require hacks
|
957
957
|
/active_support/, # active_support require hacks
|
@@ -977,7 +977,7 @@ module Sinatra
|
|
977
977
|
set :raise_errors, true
|
978
978
|
set :dump_errors, false
|
979
979
|
set :clean_trace, true
|
980
|
-
set :show_exceptions,
|
980
|
+
set :show_exceptions, false
|
981
981
|
set :sessions, false
|
982
982
|
set :logging, false
|
983
983
|
set :methodoverride, false
|
@@ -1048,6 +1048,7 @@ module Sinatra
|
|
1048
1048
|
# Base class for classic style (top-level) applications.
|
1049
1049
|
class Default < Base
|
1050
1050
|
set :raise_errors, Proc.new { test? }
|
1051
|
+
set :show_exceptions, Proc.new { development? }
|
1051
1052
|
set :dump_errors, true
|
1052
1053
|
set :sessions, false
|
1053
1054
|
set :logging, Proc.new { ! test? }
|
data/sinatra.gemspec
CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'sinatra'
|
6
|
-
s.version = '0.9.
|
7
|
-
s.date = '2009-
|
6
|
+
s.version = '0.9.4'
|
7
|
+
s.date = '2009-07-26'
|
8
8
|
|
9
9
|
s.description = "Classy web-development dressed in a DSL"
|
10
10
|
s.summary = "Classy web-development dressed in a DSL"
|
@@ -96,6 +96,7 @@ Gem::Specification.new do |s|
|
|
96
96
|
test/views/error.erb
|
97
97
|
test/views/error.haml
|
98
98
|
test/views/error.sass
|
99
|
+
test/views/foo/hello.test
|
99
100
|
test/views/hello.builder
|
100
101
|
test/views/hello.erb
|
101
102
|
test/views/hello.haml
|
data/test/options_test.rb
CHANGED
@@ -183,10 +183,15 @@ class OptionsTest < Test::Unit::TestCase
|
|
183
183
|
end
|
184
184
|
|
185
185
|
describe 'show_exceptions' do
|
186
|
+
%w[development test production none].each do |environment|
|
187
|
+
it "is disabled on Base in #{environment} environments" do
|
188
|
+
@base.set(:environment, environment)
|
189
|
+
assert ! @base.show_exceptions?
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
186
193
|
it 'is enabled on Default only in development' do
|
187
194
|
@base.set(:environment, :development)
|
188
|
-
assert @base.show_exceptions?
|
189
|
-
|
190
195
|
assert @default.development?
|
191
196
|
assert @default.show_exceptions?
|
192
197
|
|
data/test/server_test.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Rack::Handler
|
4
|
+
class Mock
|
5
|
+
extend Test::Unit::Assertions
|
6
|
+
|
7
|
+
def self.run(app, options={})
|
8
|
+
assert(app < Sinatra::Base)
|
9
|
+
assert_equal 9001, options[:Port]
|
10
|
+
assert_equal 'foo.local', options[:Host]
|
11
|
+
yield new
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
|
-
|
14
|
-
end
|
18
|
+
register 'mock', 'Rack::Handler::Mock'
|
15
19
|
end
|
16
20
|
|
17
21
|
class ServerTest < Test::Unit::TestCase
|
data/test/templates_test.rb
CHANGED
@@ -76,6 +76,12 @@ class TemplatesTest < Test::Unit::TestCase
|
|
76
76
|
assert_equal "X\n= yield\nX\n", @app.templates[:layout][:template]
|
77
77
|
end
|
78
78
|
|
79
|
+
it 'loads templates from specified views directory' do
|
80
|
+
render_app { render :test, :hello, :views => options.views + '/foo' }
|
81
|
+
|
82
|
+
assert_equal "from another views directory\n", body
|
83
|
+
end
|
84
|
+
|
79
85
|
test 'use_in_file_templates simply ignores IO errors' do
|
80
86
|
assert_nothing_raised {
|
81
87
|
mock_app {
|
@@ -85,6 +91,22 @@ class TemplatesTest < Test::Unit::TestCase
|
|
85
91
|
|
86
92
|
assert @app.templates.empty?
|
87
93
|
end
|
94
|
+
|
95
|
+
it 'passes locals to the layout' do
|
96
|
+
mock_app {
|
97
|
+
template :my_layout do
|
98
|
+
'Hello <%= name %>!<%= yield %>'
|
99
|
+
end
|
100
|
+
|
101
|
+
get '/' do
|
102
|
+
erb '<p>content</p>', { :layout => :my_layout }, { :name => 'Mike'}
|
103
|
+
end
|
104
|
+
}
|
105
|
+
|
106
|
+
get '/'
|
107
|
+
assert ok?
|
108
|
+
assert_equal 'Hello Mike!<p>content</p>', body
|
109
|
+
end
|
88
110
|
end
|
89
111
|
|
90
112
|
# __END__ : this is not the real end of the script.
|
@@ -0,0 +1 @@
|
|
1
|
+
from another views directory
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Mizerany
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- test/views/error.erb
|
138
138
|
- test/views/error.haml
|
139
139
|
- test/views/error.sass
|
140
|
+
- test/views/foo/hello.test
|
140
141
|
- test/views/hello.builder
|
141
142
|
- test/views/hello.erb
|
142
143
|
- test/views/hello.haml
|
@@ -148,6 +149,8 @@ files:
|
|
148
149
|
- test/views/layout2.test
|
149
150
|
has_rdoc: true
|
150
151
|
homepage: http://sinatra.rubyforge.org
|
152
|
+
licenses: []
|
153
|
+
|
151
154
|
post_install_message:
|
152
155
|
rdoc_options:
|
153
156
|
- --line-numbers
|
@@ -173,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
176
|
requirements: []
|
174
177
|
|
175
178
|
rubyforge_project: sinatra
|
176
|
-
rubygems_version: 1.3.
|
179
|
+
rubygems_version: 1.3.4
|
177
180
|
signing_key:
|
178
181
|
specification_version: 2
|
179
182
|
summary: Classy web-development dressed in a DSL
|