darkhelmet-sinatra 0.9.1.1 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +2 -0
- data/CHANGES +180 -0
- data/LICENSE +1 -1
- data/README.jp.rdoc +552 -0
- data/README.rdoc +177 -38
- data/Rakefile +18 -25
- data/lib/sinatra.rb +1 -2
- data/lib/sinatra/base.rb +405 -305
- data/lib/sinatra/main.rb +5 -24
- data/lib/sinatra/showexceptions.rb +303 -0
- data/lib/sinatra/tilt.rb +509 -0
- data/sinatra.gemspec +21 -51
- data/test/base_test.rb +123 -93
- data/test/builder_test.rb +2 -1
- data/test/contest.rb +64 -0
- data/test/erb_test.rb +1 -1
- data/test/erubis_test.rb +82 -0
- data/test/extensions_test.rb +24 -8
- data/test/filter_test.rb +99 -3
- data/test/haml_test.rb +25 -3
- data/test/helper.rb +43 -48
- data/test/helpers_test.rb +500 -424
- data/test/mapped_error_test.rb +163 -137
- data/test/middleware_test.rb +3 -3
- data/test/request_test.rb +16 -1
- data/test/response_test.rb +2 -2
- data/test/result_test.rb +1 -1
- data/test/route_added_hook_test.rb +59 -0
- data/test/routing_test.rb +170 -22
- data/test/sass_test.rb +44 -1
- data/test/server_test.rb +19 -13
- data/test/sinatra_test.rb +1 -1
- data/test/static_test.rb +9 -2
- data/test/templates_test.rb +78 -11
- data/test/views/error.builder +3 -0
- data/test/views/error.erb +3 -0
- data/test/views/error.erubis +3 -0
- data/test/views/error.haml +3 -0
- data/test/views/error.sass +2 -0
- data/test/views/foo/hello.test +1 -0
- data/test/views/hello.erubis +1 -0
- data/test/views/layout2.erubis +2 -0
- metadata +37 -55
- data/compat/app_test.rb +0 -282
- data/compat/application_test.rb +0 -262
- data/compat/builder_test.rb +0 -101
- data/compat/compat_test.rb +0 -12
- data/compat/custom_error_test.rb +0 -62
- data/compat/erb_test.rb +0 -136
- data/compat/events_test.rb +0 -78
- data/compat/filter_test.rb +0 -30
- data/compat/haml_test.rb +0 -233
- data/compat/helper.rb +0 -30
- data/compat/mapped_error_test.rb +0 -72
- data/compat/pipeline_test.rb +0 -45
- data/compat/public/foo.xml +0 -1
- data/compat/sass_test.rb +0 -57
- data/compat/sessions_test.rb +0 -42
- data/compat/streaming_test.rb +0 -133
- data/compat/sym_params_test.rb +0 -19
- data/compat/template_test.rb +0 -30
- data/compat/use_in_file_templates_test.rb +0 -47
- data/compat/views/foo.builder +0 -1
- data/compat/views/foo.erb +0 -1
- data/compat/views/foo.haml +0 -1
- data/compat/views/foo.sass +0 -2
- data/compat/views/foo_layout.erb +0 -2
- data/compat/views/foo_layout.haml +0 -2
- data/compat/views/layout_test/foo.builder +0 -1
- data/compat/views/layout_test/foo.erb +0 -1
- data/compat/views/layout_test/foo.haml +0 -1
- data/compat/views/layout_test/foo.sass +0 -2
- data/compat/views/layout_test/layout.builder +0 -3
- data/compat/views/layout_test/layout.erb +0 -1
- data/compat/views/layout_test/layout.haml +0 -1
- data/compat/views/layout_test/layout.sass +0 -2
- data/compat/views/no_layout/no_layout.builder +0 -1
- data/compat/views/no_layout/no_layout.haml +0 -1
- data/lib/sinatra/compat.rb +0 -250
- data/lib/sinatra/test.rb +0 -126
- data/lib/sinatra/test/bacon.rb +0 -19
- data/lib/sinatra/test/rspec.rb +0 -13
- data/lib/sinatra/test/spec.rb +0 -11
- data/lib/sinatra/test/unit.rb +0 -13
- data/test/data/reload_app_file.rb +0 -3
- data/test/options_test.rb +0 -374
- data/test/reload_test.rb +0 -68
- data/test/test_test.rb +0 -144
data/compat/views/foo.builder
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
xml.exclaim "You rock #{@name}!"
|
data/compat/views/foo.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
You rock <%= @name %>!
|
data/compat/views/foo.haml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
== You rock #{@name}!
|
data/compat/views/foo.sass
DELETED
data/compat/views/foo_layout.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
xml.this "is foo!"
|
@@ -1 +0,0 @@
|
|
1
|
-
This is foo!
|
@@ -1 +0,0 @@
|
|
1
|
-
This is foo!
|
@@ -1 +0,0 @@
|
|
1
|
-
x <%= yield %> x
|
@@ -1 +0,0 @@
|
|
1
|
-
== x #{yield} x
|
@@ -1 +0,0 @@
|
|
1
|
-
xml.foo "No Layout!"
|
@@ -1 +0,0 @@
|
|
1
|
-
%h1 No Layout!
|
data/lib/sinatra/compat.rb
DELETED
@@ -1,250 +0,0 @@
|
|
1
|
-
# Sinatra 0.3.x compatibility module.
|
2
|
-
#
|
3
|
-
# The following code makes Sinatra 0.9.x compatible with Sinatra 0.3.x to
|
4
|
-
# ease the transition to the final 1.0 release. Everything defined in this
|
5
|
-
# file will be removed for the 1.0 release.
|
6
|
-
|
7
|
-
require 'ostruct'
|
8
|
-
require 'sinatra/base'
|
9
|
-
require 'sinatra/main'
|
10
|
-
|
11
|
-
# Like Kernel#warn but outputs the location that triggered the warning.
|
12
|
-
def sinatra_warn(*message) #:nodoc:
|
13
|
-
line = caller.
|
14
|
-
detect { |line| line !~ /(?:lib\/sinatra\/|__DELEGATE__)/ }.
|
15
|
-
sub(/:in .*/, '')
|
16
|
-
warn "#{line}: warning: #{message.join(' ')}"
|
17
|
-
end
|
18
|
-
|
19
|
-
# Rack now supports evented and swiftiplied mongrels through separate
|
20
|
-
# handler.
|
21
|
-
if ENV['SWIFT']
|
22
|
-
sinatra_warn 'the SWIFT environment variable is deprecated;',
|
23
|
-
'use Rack::Handler::SwiftipliedMongrel instead.'
|
24
|
-
require 'swiftcore/swiftiplied_mongrel'
|
25
|
-
puts "Using Swiftiplied Mongrel"
|
26
|
-
elsif ENV['EVENT']
|
27
|
-
sinatra_warn 'the EVENT environment variable is deprecated;',
|
28
|
-
'use Rack::Handler::EventedMongrel instead.'
|
29
|
-
require 'swiftcore/evented_mongrel'
|
30
|
-
puts "Using Evented Mongrel"
|
31
|
-
end
|
32
|
-
|
33
|
-
# Make Rack 0.9.0 backward compatibile with 0.4.0 mime types. This isn't
|
34
|
-
# technically a Sinatra issue but many Sinatra apps access the old
|
35
|
-
# MIME_TYPES constants due to Sinatra example code.
|
36
|
-
require 'rack/file'
|
37
|
-
module Rack #:nodoc:
|
38
|
-
class File #:nodoc:
|
39
|
-
def self.const_missing(const_name)
|
40
|
-
if const_name == :MIME_TYPES
|
41
|
-
hash = Hash.new { |hash,key| Rack::Mime::MIME_TYPES[".#{key}"] }
|
42
|
-
const_set :MIME_TYPES, hash
|
43
|
-
sinatra_warn 'Rack::File::MIME_TYPES is deprecated; use Rack::Mime instead.'
|
44
|
-
hash
|
45
|
-
else
|
46
|
-
super
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module Sinatra
|
53
|
-
module Compat #:nodoc:
|
54
|
-
end
|
55
|
-
|
56
|
-
# Make Sinatra::EventContext an alias for Sinatra::Default to unbreak plugins.
|
57
|
-
def self.const_missing(const_name) #:nodoc:
|
58
|
-
if const_name == :EventContext
|
59
|
-
const_set :EventContext, Sinatra::Default
|
60
|
-
sinatra_warn 'Sinatra::EventContext is deprecated; use Sinatra::Default instead.'
|
61
|
-
Sinatra::Default
|
62
|
-
else
|
63
|
-
super
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# The ServerError exception is deprecated. Any exception is considered an
|
68
|
-
# internal server error.
|
69
|
-
class ServerError < RuntimeError
|
70
|
-
def initialize(*args, &block)
|
71
|
-
sinatra_warn 'Sinatra::ServerError is deprecated;',
|
72
|
-
'use another exception, error, or Kernel#fail instead.'
|
73
|
-
end
|
74
|
-
def code ; 500 ; end
|
75
|
-
end
|
76
|
-
|
77
|
-
class Default < Base
|
78
|
-
def self.const_missing(const_name) #:nodoc:
|
79
|
-
if const_name == :FORWARD_METHODS
|
80
|
-
sinatra_warn 'Sinatra::Application::FORWARD_METHODS is deprecated;',
|
81
|
-
'use Sinatra::Delegator::METHODS instead.'
|
82
|
-
const_set :FORWARD_METHODS, Sinatra::Delegator::METHODS
|
83
|
-
Sinatra::Delegator::METHODS
|
84
|
-
else
|
85
|
-
super
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Deprecated. Use: response['Header-Name']
|
90
|
-
def header(header=nil)
|
91
|
-
sinatra_warn "The 'header' method is deprecated; use 'headers' instead."
|
92
|
-
headers(header)
|
93
|
-
end
|
94
|
-
|
95
|
-
# Deprecated. Use: halt
|
96
|
-
def stop(*args, &block)
|
97
|
-
sinatra_warn "The 'stop' method is deprecated; use 'halt' instead."
|
98
|
-
halt(*args, &block)
|
99
|
-
end
|
100
|
-
|
101
|
-
# Deprecated. Use: etag
|
102
|
-
def entity_tag(*args, &block)
|
103
|
-
sinatra_warn "The 'entity_tag' method is deprecated; use 'etag' instead."
|
104
|
-
etag(*args, &block)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Deprecated. Use the #attachment helper and return the data as a String or
|
108
|
-
# Array.
|
109
|
-
def send_data(data, options={})
|
110
|
-
sinatra_warn "The 'send_data' method is deprecated. use attachment, status, content_type, etc. helpers instead."
|
111
|
-
|
112
|
-
status options[:status] if options[:status]
|
113
|
-
attachment options[:filename] if options[:disposition] == 'attachment'
|
114
|
-
content_type options[:type] if options[:type]
|
115
|
-
halt data
|
116
|
-
end
|
117
|
-
|
118
|
-
# Throwing halt with a Symbol and the to_result convention are
|
119
|
-
# deprecated. Override the invoke method to detect those types of return
|
120
|
-
# values.
|
121
|
-
def invoke(&block) #:nodoc:
|
122
|
-
res = super
|
123
|
-
case
|
124
|
-
when res.kind_of?(Symbol)
|
125
|
-
sinatra_warn "Invoking the :#{res} helper by returning a Symbol is deprecated;",
|
126
|
-
"call the helper directly instead."
|
127
|
-
@response.body = __send__(res)
|
128
|
-
when res.respond_to?(:to_result)
|
129
|
-
sinatra_warn "The to_result convention is deprecated."
|
130
|
-
@response.body = res.to_result(self)
|
131
|
-
end
|
132
|
-
res
|
133
|
-
end
|
134
|
-
|
135
|
-
def options #:nodoc:
|
136
|
-
Options.new(self.class)
|
137
|
-
end
|
138
|
-
|
139
|
-
class Options < Struct.new(:target) #:nodoc:
|
140
|
-
def method_missing(name, *args, &block)
|
141
|
-
if target.respond_to?(name)
|
142
|
-
target.__send__(name, *args, &block)
|
143
|
-
elsif args.empty? && name.to_s !~ /=$/
|
144
|
-
sinatra_warn 'accessing undefined options will raise a NameError in Sinatra 1.0'
|
145
|
-
nil
|
146
|
-
else
|
147
|
-
super
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
class << self
|
153
|
-
# Deprecated. Options are stored directly on the class object.
|
154
|
-
def options
|
155
|
-
sinatra_warn "The 'options' class method is deprecated; use 'self' instead."
|
156
|
-
Options.new(self)
|
157
|
-
end
|
158
|
-
|
159
|
-
# Deprecated. Use: configure
|
160
|
-
def configures(*args, &block)
|
161
|
-
sinatra_warn "The 'configures' method is deprecated; use 'configure' instead."
|
162
|
-
configure(*args, &block)
|
163
|
-
end
|
164
|
-
|
165
|
-
# Deprecated. Use: set
|
166
|
-
def default_options
|
167
|
-
sinatra_warn "Sinatra::Application.default_options is deprecated; use 'set' instead."
|
168
|
-
fake = lambda { |options| set(options) }
|
169
|
-
def fake.merge!(options) ; call(options) ; end
|
170
|
-
fake
|
171
|
-
end
|
172
|
-
|
173
|
-
# Deprecated. Use: set
|
174
|
-
def set_option(*args, &block)
|
175
|
-
sinatra_warn "The 'set_option' method is deprecated; use 'set' instead."
|
176
|
-
set(*args, &block)
|
177
|
-
end
|
178
|
-
|
179
|
-
def set_options(*args, &block)
|
180
|
-
sinatra_warn "The 'set_options' method is deprecated; use 'set' instead."
|
181
|
-
set(*args, &block)
|
182
|
-
end
|
183
|
-
|
184
|
-
# Deprecated. Use: set :environment, ENV
|
185
|
-
def env=(value)
|
186
|
-
sinatra_warn "The :env option is deprecated; use :environment instead."
|
187
|
-
set :environment, value
|
188
|
-
end
|
189
|
-
|
190
|
-
# Deprecated. Use: options.environment
|
191
|
-
def env
|
192
|
-
sinatra_warn "The :env option is deprecated; use :environment instead."
|
193
|
-
environment
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
# Deprecated. Missing messages are no longer delegated to @response.
|
198
|
-
def method_missing(name, *args, &b) #:nodoc:
|
199
|
-
if @response.respond_to?(name)
|
200
|
-
sinatra_warn "The '#{name}' method is deprecated; use 'response.#{name}' instead."
|
201
|
-
@response.send(name, *args, &b)
|
202
|
-
else
|
203
|
-
super
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
class << self
|
209
|
-
# Deprecated. Use: Sinatra::Application
|
210
|
-
def application
|
211
|
-
sinatra_warn "Sinatra.application is deprecated; use Sinatra::Application instead."
|
212
|
-
Sinatra::Application
|
213
|
-
end
|
214
|
-
|
215
|
-
# Deprecated. Use: Sinatra::Application.reset!
|
216
|
-
def application=(value)
|
217
|
-
raise ArgumentError unless value.nil?
|
218
|
-
sinatra_warn "Setting Sinatra.application to nil is deprecated; create a new instance instead."
|
219
|
-
Sinatra.class_eval do
|
220
|
-
remove_const :Application
|
221
|
-
const_set :Application, Class.new(Sinatra::Default)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def build_application
|
226
|
-
sinatra_warn "Sinatra.build_application is deprecated; use Sinatra::Application instead."
|
227
|
-
Sinatra::Application
|
228
|
-
end
|
229
|
-
|
230
|
-
def options
|
231
|
-
sinatra_warn "Sinatra.options is deprecated; use Sinatra::Application.option_name instead."
|
232
|
-
Sinatra::Application.options
|
233
|
-
end
|
234
|
-
|
235
|
-
def port
|
236
|
-
sinatra_warn "Sinatra.port is deprecated; use Sinatra::Application.port instead."
|
237
|
-
options.port
|
238
|
-
end
|
239
|
-
|
240
|
-
def host
|
241
|
-
sinatra_warn "Sinatra.host is deprecated; use Sinatra::Application.host instead."
|
242
|
-
options.host
|
243
|
-
end
|
244
|
-
|
245
|
-
def env
|
246
|
-
sinatra_warn "Sinatra.env is deprecated; use Sinatra::Application.environment instead."
|
247
|
-
options.environment
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
data/lib/sinatra/test.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
|
3
|
-
module Sinatra
|
4
|
-
module Test
|
5
|
-
include Rack::Utils
|
6
|
-
|
7
|
-
def self.included(base)
|
8
|
-
Sinatra::Default.set(:environment, :test)
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :app, :request, :response
|
12
|
-
|
13
|
-
def self.deprecate(framework)
|
14
|
-
warn <<-EOF
|
15
|
-
Warning: support for the #{framework} testing framework is deprecated and
|
16
|
-
will be dropped in Sinatra 1.0. See <http://sinatra.github.com/testing.html>
|
17
|
-
for more information.
|
18
|
-
EOF
|
19
|
-
end
|
20
|
-
|
21
|
-
def make_request(verb, path, body=nil, options={})
|
22
|
-
@app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application)
|
23
|
-
fail "@app not set - cannot make request" if @app.nil?
|
24
|
-
|
25
|
-
@request = Rack::MockRequest.new(@app)
|
26
|
-
options = { :lint => true }.merge(options || {})
|
27
|
-
|
28
|
-
case
|
29
|
-
when body.respond_to?(:to_hash)
|
30
|
-
options.merge! body.delete(:env) if body.key?(:env)
|
31
|
-
options[:input] = param_string(body)
|
32
|
-
when body.respond_to?(:to_str)
|
33
|
-
options[:input] = body
|
34
|
-
when body.nil?
|
35
|
-
options[:input] = ''
|
36
|
-
else
|
37
|
-
raise ArgumentError, "body must be a Hash, String, or nil"
|
38
|
-
end
|
39
|
-
|
40
|
-
yield @request if block_given?
|
41
|
-
@response = @request.request(verb, path, rack_options(options))
|
42
|
-
end
|
43
|
-
|
44
|
-
def get(path, *args, &b) ; make_request('GET', path, *args, &b) ; end
|
45
|
-
def head(path, *args, &b) ; make_request('HEAD', path, *args, &b) ; end
|
46
|
-
def post(path, *args, &b) ; make_request('POST', path, *args, &b) ; end
|
47
|
-
def put(path, *args, &b) ; make_request('PUT', path, *args, &b) ; end
|
48
|
-
def delete(path, *args, &b) ; make_request('DELETE', path, *args, &b) ; end
|
49
|
-
|
50
|
-
def follow!
|
51
|
-
make_request 'GET', @response.location
|
52
|
-
end
|
53
|
-
|
54
|
-
def body ; @response.body ; end
|
55
|
-
def status ; @response.status ; end
|
56
|
-
|
57
|
-
# Delegate other missing methods to @response.
|
58
|
-
def method_missing(name, *args, &block)
|
59
|
-
if @response && @response.respond_to?(name)
|
60
|
-
@response.send(name, *args, &block)
|
61
|
-
else
|
62
|
-
super
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Also check @response since we delegate there.
|
67
|
-
def respond_to?(symbol, include_private=false)
|
68
|
-
super || (@response && @response.respond_to?(symbol, include_private))
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
RACK_OPTIONS = {
|
74
|
-
:accept => 'HTTP_ACCEPT',
|
75
|
-
:agent => 'HTTP_USER_AGENT',
|
76
|
-
:host => 'HTTP_HOST',
|
77
|
-
:session => 'rack.session',
|
78
|
-
:cookies => 'HTTP_COOKIE',
|
79
|
-
:content_type => 'CONTENT_TYPE'
|
80
|
-
}
|
81
|
-
|
82
|
-
def rack_options(opts)
|
83
|
-
opts.merge(:lint => true).inject({}) do |hash,(key,val)|
|
84
|
-
key = RACK_OPTIONS[key] || key
|
85
|
-
hash[key] = val
|
86
|
-
hash
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def param_string(value, prefix = nil)
|
91
|
-
case value
|
92
|
-
when Array
|
93
|
-
value.map { |v|
|
94
|
-
param_string(v, "#{prefix}[]")
|
95
|
-
} * "&"
|
96
|
-
when Hash
|
97
|
-
value.map { |k, v|
|
98
|
-
param_string(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
|
99
|
-
} * "&"
|
100
|
-
else
|
101
|
-
"#{prefix}=#{escape(value)}"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
if defined? Sinatra::Compat
|
106
|
-
# Deprecated. Use: "get" instead of "get_it".
|
107
|
-
%w(get head post put delete).each do |verb|
|
108
|
-
eval <<-RUBY, binding, __FILE__, __LINE__
|
109
|
-
def #{verb}_it(*args, &block)
|
110
|
-
sinatra_warn "The #{verb}_it method is deprecated; use #{verb} instead."
|
111
|
-
make_request('#{verb.upcase}', *args, &block)
|
112
|
-
end
|
113
|
-
RUBY
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
class TestHarness
|
119
|
-
include Test
|
120
|
-
|
121
|
-
def initialize(app=nil)
|
122
|
-
@app = app || Sinatra::Application
|
123
|
-
@app.set(:environment, :test)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
data/lib/sinatra/test/bacon.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'bacon'
|
2
|
-
require 'sinatra/test'
|
3
|
-
|
4
|
-
Sinatra::Test.deprecate('Bacon')
|
5
|
-
|
6
|
-
Sinatra::Default.set(
|
7
|
-
:environment => :test,
|
8
|
-
:run => false,
|
9
|
-
:raise_errors => true,
|
10
|
-
:logging => false
|
11
|
-
)
|
12
|
-
|
13
|
-
module Sinatra::Test
|
14
|
-
def should
|
15
|
-
@response.should
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Bacon::Context.send(:include, Sinatra::Test)
|