sinatra-sinatra 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +40 -0
- data/CHANGES +174 -0
- data/LICENSE +22 -0
- data/README.rdoc +545 -0
- data/Rakefile +180 -0
- data/compat/app_test.rb +300 -0
- data/compat/application_test.rb +334 -0
- data/compat/builder_test.rb +101 -0
- data/compat/custom_error_test.rb +62 -0
- data/compat/erb_test.rb +136 -0
- data/compat/events_test.rb +78 -0
- data/compat/filter_test.rb +30 -0
- data/compat/haml_test.rb +233 -0
- data/compat/helper.rb +30 -0
- data/compat/mapped_error_test.rb +72 -0
- data/compat/pipeline_test.rb +71 -0
- data/compat/public/foo.xml +1 -0
- data/compat/sass_test.rb +57 -0
- data/compat/sessions_test.rb +39 -0
- data/compat/streaming_test.rb +121 -0
- data/compat/sym_params_test.rb +19 -0
- data/compat/template_test.rb +30 -0
- data/compat/use_in_file_templates_test.rb +47 -0
- data/compat/views/foo.builder +1 -0
- data/compat/views/foo.erb +1 -0
- data/compat/views/foo.haml +1 -0
- data/compat/views/foo.sass +2 -0
- data/compat/views/foo_layout.erb +2 -0
- data/compat/views/foo_layout.haml +2 -0
- data/compat/views/layout_test/foo.builder +1 -0
- data/compat/views/layout_test/foo.erb +1 -0
- data/compat/views/layout_test/foo.haml +1 -0
- data/compat/views/layout_test/foo.sass +2 -0
- data/compat/views/layout_test/layout.builder +3 -0
- data/compat/views/layout_test/layout.erb +1 -0
- data/compat/views/layout_test/layout.haml +1 -0
- data/compat/views/layout_test/layout.sass +2 -0
- data/compat/views/no_layout/no_layout.builder +1 -0
- data/compat/views/no_layout/no_layout.haml +1 -0
- data/lib/sinatra/base.rb +818 -0
- data/lib/sinatra/compat.rb +239 -0
- data/lib/sinatra/images/404.png +0 -0
- data/lib/sinatra/images/500.png +0 -0
- data/lib/sinatra/main.rb +48 -0
- data/lib/sinatra/test/bacon.rb +17 -0
- data/lib/sinatra/test/rspec.rb +9 -0
- data/lib/sinatra/test/spec.rb +9 -0
- data/lib/sinatra/test/unit.rb +11 -0
- data/lib/sinatra/test.rb +109 -0
- data/lib/sinatra.rb +4 -0
- data/sinatra.gemspec +109 -0
- data/test/base_test.rb +68 -0
- data/test/builder_test.rb +64 -0
- data/test/data/reload_app_file.rb +3 -0
- data/test/erb_test.rb +50 -0
- data/test/filter_test.rb +35 -0
- data/test/haml_test.rb +68 -0
- data/test/helper.rb +20 -0
- data/test/helpers_test.rb +361 -0
- data/test/mapped_error_test.rb +160 -0
- data/test/middleware_test.rb +58 -0
- data/test/options_test.rb +97 -0
- data/test/reload_test.rb +61 -0
- data/test/request_test.rb +9 -0
- data/test/result_test.rb +88 -0
- data/test/routing_test.rb +334 -0
- data/test/sass_test.rb +36 -0
- data/test/sinatra_test.rb +13 -0
- data/test/static_test.rb +57 -0
- data/test/templates_test.rb +88 -0
- data/test/views/hello.builder +1 -0
- data/test/views/hello.erb +1 -0
- data/test/views/hello.haml +1 -0
- data/test/views/hello.sass +2 -0
- data/test/views/hello.test +1 -0
- data/test/views/layout2.builder +3 -0
- data/test/views/layout2.erb +2 -0
- data/test/views/layout2.haml +2 -0
- data/test/views/layout2.test +1 -0
- metadata +161 -0
@@ -0,0 +1,239 @@
|
|
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)
|
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
|
+
class Rack::File
|
38
|
+
def self.const_missing(const_name)
|
39
|
+
if const_name == :MIME_TYPES
|
40
|
+
hash = Hash.new { |hash,key| Rack::Mime::MIME_TYPES[".#{key}"] }
|
41
|
+
const_set :MIME_TYPES, hash
|
42
|
+
sinatra_warn 'Rack::File::MIME_TYPES is deprecated; use Rack::Mime instead.'
|
43
|
+
hash
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Sinatra
|
51
|
+
module Compat
|
52
|
+
end
|
53
|
+
|
54
|
+
# The ServerError exception is deprecated. Any exception is considered an
|
55
|
+
# internal server error.
|
56
|
+
class ServerError < RuntimeError
|
57
|
+
def initialize(*args, &block)
|
58
|
+
sinatra_warn 'Sinatra::ServerError is deprecated;',
|
59
|
+
'use another exception, error, or Kernel#fail instead.'
|
60
|
+
end
|
61
|
+
def code ; 500 ; end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Default < Base
|
65
|
+
def self.const_missing(const_name)
|
66
|
+
if const_name == :FORWARD_METHODS
|
67
|
+
sinatra_warn 'Sinatra::Application::FORWARD_METHODS is deprecated;',
|
68
|
+
'use Sinatra::Delegator::METHODS instead.'
|
69
|
+
const_set :FORWARD_METHODS, Sinatra::Delegator::METHODS
|
70
|
+
Sinatra::Delegator::METHODS
|
71
|
+
else
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Deprecated. Use: response['Header-Name']
|
77
|
+
def headers(header=nil)
|
78
|
+
sinatra_warn "The 'headers' method is deprecated; use 'response' instead."
|
79
|
+
response.headers.merge!(header) if header
|
80
|
+
response.headers
|
81
|
+
end
|
82
|
+
alias :header :headers
|
83
|
+
|
84
|
+
# Deprecated. Use: halt
|
85
|
+
def stop(*args, &block)
|
86
|
+
sinatra_warn "The 'stop' method is deprecated; use 'halt' instead."
|
87
|
+
halt(*args, &block)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Deprecated. Use: etag
|
91
|
+
def entity_tag(*args, &block)
|
92
|
+
sinatra_warn "The 'entity_tag' method is deprecated; use 'etag' instead."
|
93
|
+
etag(*args, &block)
|
94
|
+
end
|
95
|
+
|
96
|
+
# The :disposition option is deprecated; use: #attachment. This method
|
97
|
+
# setting the Content-Transfer-Encoding header is deprecated.
|
98
|
+
#--
|
99
|
+
# TODO deprecation warning for :disposition argument.
|
100
|
+
def send_file(path, opts={})
|
101
|
+
opts[:disposition] = 'attachment' if !opts.key?(:disposition)
|
102
|
+
attachment opts[:filename] || path if opts[:filename] || opts[:disposition]
|
103
|
+
response['Content-Transfer-Encoding'] = 'binary' if opts[:disposition]
|
104
|
+
super(path, opts)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Throwing halt with a Symbol and the to_result convention are
|
108
|
+
# deprecated. Override the invoke method to detect those types of return
|
109
|
+
# values.
|
110
|
+
def invoke(handler)
|
111
|
+
res = super
|
112
|
+
case
|
113
|
+
when res.kind_of?(Symbol)
|
114
|
+
sinatra_warn "Invoking the :#{res} helper by returning a Symbol is deprecated;",
|
115
|
+
"call the helper directly instead."
|
116
|
+
@response.body = __send__(res)
|
117
|
+
when res.respond_to?(:to_result)
|
118
|
+
sinatra_warn "The to_result convention is deprecated."
|
119
|
+
@response.body = res.to_result(self)
|
120
|
+
end
|
121
|
+
res
|
122
|
+
end
|
123
|
+
|
124
|
+
def options
|
125
|
+
Options.new(self.class)
|
126
|
+
end
|
127
|
+
|
128
|
+
class Options < Struct.new(:target) #:nodoc:
|
129
|
+
def method_missing(name, *args, &block)
|
130
|
+
if target.respond_to?(name)
|
131
|
+
target.__send__(name, *args, &block)
|
132
|
+
elsif args.empty? && name.to_s !~ /=$/
|
133
|
+
sinatra_warn 'accessing undefined options will raise a NameError in Sinatra 1.0'
|
134
|
+
nil
|
135
|
+
else
|
136
|
+
super
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class << self
|
142
|
+
# Deprecated. Options are stored directly on the class object.
|
143
|
+
def options
|
144
|
+
sinatra_warn "The 'options' class method is deprecated; use 'self' instead."
|
145
|
+
Options.new(self)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Deprecated. Use: configure
|
149
|
+
def configures(*args, &block)
|
150
|
+
sinatra_warn "The 'configures' method is deprecated; use 'configure' instead."
|
151
|
+
configure(*args, &block)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Deprecated. Use: set
|
155
|
+
def default_options
|
156
|
+
sinatra_warn "Sinatra::Application.default_options is deprecated; use 'set' instead."
|
157
|
+
fake = lambda { |options| set(options) }
|
158
|
+
def fake.merge!(options) ; call(options) ; end
|
159
|
+
fake
|
160
|
+
end
|
161
|
+
|
162
|
+
# Deprecated. Use: set
|
163
|
+
def set_option(*args, &block)
|
164
|
+
sinatra_warn "The 'set_option' method is deprecated; use 'set' instead."
|
165
|
+
set(*args, &block)
|
166
|
+
end
|
167
|
+
|
168
|
+
def set_options(*args, &block)
|
169
|
+
sinatra_warn "The 'set_options' method is deprecated; use 'set' instead."
|
170
|
+
set(*args, &block)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Deprecated. Use: set :environment, ENV
|
174
|
+
def env=(value)
|
175
|
+
sinatra_warn "The :env option is deprecated; use :environment instead."
|
176
|
+
set :environment, value
|
177
|
+
end
|
178
|
+
|
179
|
+
# Deprecated. Use: options.environment
|
180
|
+
def env
|
181
|
+
sinatra_warn "The :env option is deprecated; use :environment instead."
|
182
|
+
environment
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Deprecated. Missing messages are no longer delegated to @response.
|
187
|
+
def method_missing(name, *args, &b)
|
188
|
+
if @response.respond_to?(name)
|
189
|
+
sinatra_warn "The '#{name}' method is deprecated; use 'response.#{name}' instead."
|
190
|
+
@response.send(name, *args, &b)
|
191
|
+
else
|
192
|
+
super
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
class << self
|
198
|
+
# Deprecated. Use: Sinatra::Application
|
199
|
+
def application
|
200
|
+
sinatra_warn "Sinatra.application is deprecated; use Sinatra::Application instead."
|
201
|
+
Sinatra::Application
|
202
|
+
end
|
203
|
+
|
204
|
+
# Deprecated. Use: Sinatra::Application.reset!
|
205
|
+
def application=(value)
|
206
|
+
raise ArgumentError unless value.nil?
|
207
|
+
sinatra_warn "Setting Sinatra.application to nil is deprecated; create a new instance instead."
|
208
|
+
Sinatra.class_eval do
|
209
|
+
remove_const :Application
|
210
|
+
const_set :Application, Class.new(Sinatra::Default)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def build_application
|
215
|
+
sinatra_warn "Sinatra.build_application is deprecated; use Sinatra::Application instead."
|
216
|
+
Sinatra::Application
|
217
|
+
end
|
218
|
+
|
219
|
+
def options
|
220
|
+
sinatra_warn "Sinatra.options is deprecated; use Sinatra::Application.option_name instead."
|
221
|
+
Sinatra::Application.options
|
222
|
+
end
|
223
|
+
|
224
|
+
def port
|
225
|
+
sinatra_warn "Sinatra.port is deprecated; use Sinatra::Application.port instead."
|
226
|
+
options.port
|
227
|
+
end
|
228
|
+
|
229
|
+
def host
|
230
|
+
sinatra_warn "Sinatra.host is deprecated; use Sinatra::Application.host instead."
|
231
|
+
options.host
|
232
|
+
end
|
233
|
+
|
234
|
+
def env
|
235
|
+
sinatra_warn "Sinatra.env is deprecated; use Sinatra::Application.environment instead."
|
236
|
+
options.environment
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
Binary file
|
Binary file
|
data/lib/sinatra/main.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
class Default < Base
|
5
|
+
set :app_file, lambda {
|
6
|
+
ignore = [
|
7
|
+
/lib\/sinatra.*\.rb$/, # all sinatra code
|
8
|
+
/\(.*\)/, # generated code
|
9
|
+
/custom_require\.rb$/ # rubygems require hacks
|
10
|
+
]
|
11
|
+
path =
|
12
|
+
caller.map{ |line| line.split(':', 2).first }.find do |file|
|
13
|
+
next if ignore.any? { |pattern| file =~ pattern }
|
14
|
+
file
|
15
|
+
end
|
16
|
+
path || $0
|
17
|
+
}.call
|
18
|
+
|
19
|
+
set :run, Proc.new { $0 == app_file }
|
20
|
+
set :reload, Proc.new{ app_file? && development? }
|
21
|
+
|
22
|
+
if run? && ARGV.any?
|
23
|
+
require 'optparse'
|
24
|
+
OptionParser.new { |op|
|
25
|
+
op.on('-x') { set :mutex, true }
|
26
|
+
op.on('-e env') { |val| set :environment, val.to_sym }
|
27
|
+
op.on('-s server') { |val| set :server, val }
|
28
|
+
op.on('-p port') { |val| set :port, val.to_i }
|
29
|
+
}.parse!(ARGV.dup)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
include Sinatra::Delegator
|
35
|
+
|
36
|
+
def helpers(&block)
|
37
|
+
Sinatra::Application.send :class_eval, &block
|
38
|
+
end
|
39
|
+
|
40
|
+
def mime(ext, type)
|
41
|
+
ext = ".#{ext}" unless ext.to_s[0] == ?.
|
42
|
+
Rack::Mime::MIME_TYPES[ext.to_s] = type
|
43
|
+
end
|
44
|
+
|
45
|
+
at_exit do
|
46
|
+
raise $! if $!
|
47
|
+
Sinatra::Application.run! if Sinatra::Application.run?
|
48
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bacon'
|
2
|
+
require 'sinatra/test'
|
3
|
+
|
4
|
+
Sinatra::Default.set(
|
5
|
+
:env => :test,
|
6
|
+
:run => false,
|
7
|
+
:raise_errors => true,
|
8
|
+
:logging => false
|
9
|
+
)
|
10
|
+
|
11
|
+
module Sinatra::Test
|
12
|
+
def should
|
13
|
+
@response.should
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Bacon::Context.send(:include, Sinatra::Test)
|
data/lib/sinatra/test.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
|
5
|
+
module Test
|
6
|
+
include Rack::Utils
|
7
|
+
|
8
|
+
attr_reader :app, :request, :response
|
9
|
+
|
10
|
+
def test_request(verb, path, *args)
|
11
|
+
@app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application)
|
12
|
+
fail "@app not set - cannot make request" if @app.nil?
|
13
|
+
@request = Rack::MockRequest.new(@app)
|
14
|
+
opts, input =
|
15
|
+
case args.size
|
16
|
+
when 2 # input, env
|
17
|
+
input, env = args
|
18
|
+
if input.kind_of?(Hash) # params, env
|
19
|
+
[env, param_string(input)]
|
20
|
+
else
|
21
|
+
[env, input]
|
22
|
+
end
|
23
|
+
when 1 # params
|
24
|
+
if (data = args.first).kind_of?(Hash)
|
25
|
+
env = (data.delete(:env) || {})
|
26
|
+
[env, param_string(data)]
|
27
|
+
else
|
28
|
+
[{}, data]
|
29
|
+
end
|
30
|
+
when 0
|
31
|
+
[{}, '']
|
32
|
+
else
|
33
|
+
raise ArgumentError, "zero, one, or two arguments expected"
|
34
|
+
end
|
35
|
+
opts = rack_opts(opts)
|
36
|
+
opts[:input] ||= input
|
37
|
+
yield @request if block_given?
|
38
|
+
@response = @request.request(verb, path, opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get(path, *args, &b) ; test_request('GET', path, *args, &b) ; end
|
42
|
+
def head(path, *args, &b) ; test_request('HEAD', path, *args, &b) ; end
|
43
|
+
def post(path, *args, &b) ; test_request('POST', path, *args, &b) ; end
|
44
|
+
def put(path, *args, &b) ; test_request('PUT', path, *args, &b) ; end
|
45
|
+
def delete(path, *args, &b) ; test_request('DELETE', path, *args, &b) ; end
|
46
|
+
|
47
|
+
def follow!
|
48
|
+
test_request 'GET', @response.location
|
49
|
+
end
|
50
|
+
|
51
|
+
def body ; @response.body ; end
|
52
|
+
def status ; @response.status ; end
|
53
|
+
|
54
|
+
# Delegate other missing methods to @response.
|
55
|
+
def method_missing(name, *args, &block)
|
56
|
+
if @response && @response.respond_to?(name)
|
57
|
+
@response.send(name, *args, &block)
|
58
|
+
else
|
59
|
+
super
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
RACK_OPT_NAMES = {
|
64
|
+
:accept => "HTTP_ACCEPT",
|
65
|
+
:agent => "HTTP_USER_AGENT",
|
66
|
+
:host => "HTTP_HOST",
|
67
|
+
:session => "HTTP_COOKIE",
|
68
|
+
:cookies => "HTTP_COOKIE",
|
69
|
+
:content_type => "CONTENT_TYPE"
|
70
|
+
}
|
71
|
+
|
72
|
+
def rack_opts(opts)
|
73
|
+
opts.inject({}) do |hash,(key,val)|
|
74
|
+
key = RACK_OPT_NAMES[key] || key
|
75
|
+
hash[key] = val
|
76
|
+
hash
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def env_for(opts={})
|
81
|
+
opts = rack_opts(opts)
|
82
|
+
Rack::MockRequest.env_for(opts)
|
83
|
+
end
|
84
|
+
|
85
|
+
def param_string(hash)
|
86
|
+
hash.map { |pair| pair.map{|v|escape(v)}.join('=') }.join('&')
|
87
|
+
end
|
88
|
+
|
89
|
+
if defined? Sinatra::Compat
|
90
|
+
# Deprecated. Use: "get" instead of "get_it".
|
91
|
+
%w(get head post put delete).each do |verb|
|
92
|
+
eval <<-RUBY, binding, __FILE__, __LINE__
|
93
|
+
def #{verb}_it(*args, &block)
|
94
|
+
sinatra_warn "The #{verb}_it method is deprecated; use #{verb} instead."
|
95
|
+
test_request('#{verb.upcase}', *args, &block)
|
96
|
+
end
|
97
|
+
RUBY
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class TestHarness
|
103
|
+
include Test
|
104
|
+
|
105
|
+
def initialize(app=nil)
|
106
|
+
@app = app || Sinatra::Application
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/sinatra.rb
ADDED
data/sinatra.gemspec
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
|
+
|
5
|
+
s.name = 'sinatra'
|
6
|
+
s.version = '0.8.9'
|
7
|
+
s.date = '2009-01-14'
|
8
|
+
|
9
|
+
s.description = "Classy web-development dressed in a DSL"
|
10
|
+
s.summary = "Classy web-development dressed in a DSL"
|
11
|
+
|
12
|
+
s.authors = ["Blake Mizerany"]
|
13
|
+
|
14
|
+
# = MANIFEST =
|
15
|
+
s.files = %w[
|
16
|
+
AUTHORS
|
17
|
+
CHANGES
|
18
|
+
LICENSE
|
19
|
+
README.rdoc
|
20
|
+
Rakefile
|
21
|
+
compat/app_test.rb
|
22
|
+
compat/application_test.rb
|
23
|
+
compat/builder_test.rb
|
24
|
+
compat/custom_error_test.rb
|
25
|
+
compat/erb_test.rb
|
26
|
+
compat/events_test.rb
|
27
|
+
compat/filter_test.rb
|
28
|
+
compat/haml_test.rb
|
29
|
+
compat/helper.rb
|
30
|
+
compat/mapped_error_test.rb
|
31
|
+
compat/pipeline_test.rb
|
32
|
+
compat/public/foo.xml
|
33
|
+
compat/sass_test.rb
|
34
|
+
compat/sessions_test.rb
|
35
|
+
compat/streaming_test.rb
|
36
|
+
compat/sym_params_test.rb
|
37
|
+
compat/template_test.rb
|
38
|
+
compat/use_in_file_templates_test.rb
|
39
|
+
compat/views/foo.builder
|
40
|
+
compat/views/foo.erb
|
41
|
+
compat/views/foo.haml
|
42
|
+
compat/views/foo.sass
|
43
|
+
compat/views/foo_layout.erb
|
44
|
+
compat/views/foo_layout.haml
|
45
|
+
compat/views/layout_test/foo.builder
|
46
|
+
compat/views/layout_test/foo.erb
|
47
|
+
compat/views/layout_test/foo.haml
|
48
|
+
compat/views/layout_test/foo.sass
|
49
|
+
compat/views/layout_test/layout.builder
|
50
|
+
compat/views/layout_test/layout.erb
|
51
|
+
compat/views/layout_test/layout.haml
|
52
|
+
compat/views/layout_test/layout.sass
|
53
|
+
compat/views/no_layout/no_layout.builder
|
54
|
+
compat/views/no_layout/no_layout.haml
|
55
|
+
lib/sinatra.rb
|
56
|
+
lib/sinatra/base.rb
|
57
|
+
lib/sinatra/compat.rb
|
58
|
+
lib/sinatra/images/404.png
|
59
|
+
lib/sinatra/images/500.png
|
60
|
+
lib/sinatra/main.rb
|
61
|
+
lib/sinatra/test.rb
|
62
|
+
lib/sinatra/test/bacon.rb
|
63
|
+
lib/sinatra/test/rspec.rb
|
64
|
+
lib/sinatra/test/spec.rb
|
65
|
+
lib/sinatra/test/unit.rb
|
66
|
+
sinatra.gemspec
|
67
|
+
test/base_test.rb
|
68
|
+
test/builder_test.rb
|
69
|
+
test/data/reload_app_file.rb
|
70
|
+
test/erb_test.rb
|
71
|
+
test/filter_test.rb
|
72
|
+
test/haml_test.rb
|
73
|
+
test/helper.rb
|
74
|
+
test/helpers_test.rb
|
75
|
+
test/mapped_error_test.rb
|
76
|
+
test/middleware_test.rb
|
77
|
+
test/options_test.rb
|
78
|
+
test/reload_test.rb
|
79
|
+
test/request_test.rb
|
80
|
+
test/result_test.rb
|
81
|
+
test/routing_test.rb
|
82
|
+
test/sass_test.rb
|
83
|
+
test/sinatra_test.rb
|
84
|
+
test/static_test.rb
|
85
|
+
test/templates_test.rb
|
86
|
+
test/views/hello.builder
|
87
|
+
test/views/hello.erb
|
88
|
+
test/views/hello.haml
|
89
|
+
test/views/hello.sass
|
90
|
+
test/views/hello.test
|
91
|
+
test/views/layout2.builder
|
92
|
+
test/views/layout2.erb
|
93
|
+
test/views/layout2.haml
|
94
|
+
test/views/layout2.test
|
95
|
+
]
|
96
|
+
# = MANIFEST =
|
97
|
+
|
98
|
+
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
99
|
+
|
100
|
+
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
101
|
+
s.add_dependency 'rack', '>= 0.9.0'
|
102
|
+
|
103
|
+
s.has_rdoc = true
|
104
|
+
s.homepage = "http://sinatra.rubyforge.org"
|
105
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sinatra", "--main", "README.rdoc"]
|
106
|
+
s.require_paths = %w[lib]
|
107
|
+
s.rubyforge_project = 'sinatra'
|
108
|
+
s.rubygems_version = '1.1.1'
|
109
|
+
end
|
data/test/base_test.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
describe 'Sinatra::Base' do
|
4
|
+
it 'includes Rack::Utils' do
|
5
|
+
assert Sinatra::Base.included_modules.include?(Rack::Utils)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'can be used as a Rack application' do
|
9
|
+
mock_app {
|
10
|
+
get '/' do
|
11
|
+
'Hello World'
|
12
|
+
end
|
13
|
+
}
|
14
|
+
assert @app.respond_to?(:call)
|
15
|
+
|
16
|
+
request = Rack::MockRequest.new(@app)
|
17
|
+
response = request.get('/')
|
18
|
+
assert response.ok?
|
19
|
+
assert_equal 'Hello World', response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can be used as Rack middleware' do
|
23
|
+
app = lambda { |env| [200, {}, ['Goodbye World']] }
|
24
|
+
mock_middleware =
|
25
|
+
mock_app {
|
26
|
+
get '/' do
|
27
|
+
'Hello World'
|
28
|
+
end
|
29
|
+
get '/goodbye' do
|
30
|
+
@app.call(request.env)
|
31
|
+
end
|
32
|
+
}
|
33
|
+
middleware = mock_middleware.new(app)
|
34
|
+
assert_same app, middleware.app
|
35
|
+
|
36
|
+
request = Rack::MockRequest.new(middleware)
|
37
|
+
response = request.get('/')
|
38
|
+
assert response.ok?
|
39
|
+
assert_equal 'Hello World', response.body
|
40
|
+
|
41
|
+
response = request.get('/goodbye')
|
42
|
+
assert response.ok?
|
43
|
+
assert_equal 'Goodbye World', response.body
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'can take multiple definitions of a route' do
|
47
|
+
app = mock_app {
|
48
|
+
user_agent(/Foo/)
|
49
|
+
get '/foo' do
|
50
|
+
'foo'
|
51
|
+
end
|
52
|
+
|
53
|
+
get '/foo' do
|
54
|
+
'not foo'
|
55
|
+
end
|
56
|
+
}
|
57
|
+
|
58
|
+
request = Rack::MockRequest.new(app)
|
59
|
+
response = request.get('/foo', 'HTTP_USER_AGENT' => 'Foo')
|
60
|
+
assert response.ok?
|
61
|
+
assert_equal 'foo', response.body
|
62
|
+
|
63
|
+
request = Rack::MockRequest.new(app)
|
64
|
+
response = request.get('/foo')
|
65
|
+
assert response.ok?
|
66
|
+
assert_equal 'not foo', response.body
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
describe "Builder Templates" do
|
4
|
+
def builder_app(&block)
|
5
|
+
mock_app {
|
6
|
+
set :views, File.dirname(__FILE__) + '/views'
|
7
|
+
get '/', &block
|
8
|
+
}
|
9
|
+
get '/'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'renders inline Builder strings' do
|
13
|
+
builder_app { builder 'xml.instruct!' }
|
14
|
+
assert ok?
|
15
|
+
assert_equal %{<?xml version="1.0" encoding="UTF-8"?>\n}, body
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'renders inline blocks' do
|
19
|
+
builder_app {
|
20
|
+
@name = "Frank & Mary"
|
21
|
+
builder do |xml|
|
22
|
+
xml.couple @name
|
23
|
+
end
|
24
|
+
}
|
25
|
+
assert ok?
|
26
|
+
assert_equal "<couple>Frank & Mary</couple>\n", body
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'renders .builder files in views path' do
|
30
|
+
builder_app {
|
31
|
+
@name = "Blue"
|
32
|
+
builder :hello
|
33
|
+
}
|
34
|
+
assert ok?
|
35
|
+
assert_equal %(<exclaim>You're my boy, Blue!</exclaim>\n), body
|
36
|
+
end
|
37
|
+
|
38
|
+
it "renders with inline layouts" do
|
39
|
+
mock_app {
|
40
|
+
layout do
|
41
|
+
%(xml.layout { xml << yield })
|
42
|
+
end
|
43
|
+
get('/') { builder %(xml.em 'Hello World') }
|
44
|
+
}
|
45
|
+
get '/'
|
46
|
+
assert ok?
|
47
|
+
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
|
48
|
+
end
|
49
|
+
|
50
|
+
it "renders with file layouts" do
|
51
|
+
builder_app {
|
52
|
+
builder %(xml.em 'Hello World'), :layout => :layout2
|
53
|
+
}
|
54
|
+
assert ok?
|
55
|
+
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
|
56
|
+
end
|
57
|
+
|
58
|
+
it "raises error if template not found" do
|
59
|
+
mock_app {
|
60
|
+
get('/') { builder :no_such_template }
|
61
|
+
}
|
62
|
+
assert_raise(Errno::ENOENT) { get('/') }
|
63
|
+
end
|
64
|
+
end
|