sinatra-sinatra 0.9.2 → 0.10.0

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.
Files changed (52) hide show
  1. data/CHANGES +1 -1
  2. data/README.rdoc +1 -1
  3. data/Rakefile +1 -20
  4. data/lib/sinatra.rb +0 -1
  5. data/lib/sinatra/base.rb +4 -27
  6. data/sinatra.gemspec +4 -45
  7. data/test/server_test.rb +14 -10
  8. data/test/templates_test.rb +22 -0
  9. data/test/views/foo/hello.test +1 -0
  10. metadata +4 -46
  11. data/compat/app_test.rb +0 -282
  12. data/compat/application_test.rb +0 -262
  13. data/compat/builder_test.rb +0 -101
  14. data/compat/compat_test.rb +0 -12
  15. data/compat/custom_error_test.rb +0 -62
  16. data/compat/erb_test.rb +0 -136
  17. data/compat/events_test.rb +0 -78
  18. data/compat/filter_test.rb +0 -30
  19. data/compat/haml_test.rb +0 -236
  20. data/compat/helper.rb +0 -33
  21. data/compat/mapped_error_test.rb +0 -72
  22. data/compat/pipeline_test.rb +0 -45
  23. data/compat/public/foo.xml +0 -1
  24. data/compat/sass_test.rb +0 -67
  25. data/compat/sessions_test.rb +0 -42
  26. data/compat/streaming_test.rb +0 -133
  27. data/compat/sym_params_test.rb +0 -19
  28. data/compat/template_test.rb +0 -30
  29. data/compat/use_in_file_templates_test.rb +0 -47
  30. data/compat/views/foo.builder +0 -1
  31. data/compat/views/foo.erb +0 -1
  32. data/compat/views/foo.haml +0 -1
  33. data/compat/views/foo.sass +0 -2
  34. data/compat/views/foo_layout.erb +0 -2
  35. data/compat/views/foo_layout.haml +0 -2
  36. data/compat/views/layout_test/foo.builder +0 -1
  37. data/compat/views/layout_test/foo.erb +0 -1
  38. data/compat/views/layout_test/foo.haml +0 -1
  39. data/compat/views/layout_test/foo.sass +0 -2
  40. data/compat/views/layout_test/layout.builder +0 -3
  41. data/compat/views/layout_test/layout.erb +0 -1
  42. data/compat/views/layout_test/layout.haml +0 -1
  43. data/compat/views/layout_test/layout.sass +0 -2
  44. data/compat/views/no_layout/no_layout.builder +0 -1
  45. data/compat/views/no_layout/no_layout.haml +0 -1
  46. data/lib/sinatra/compat.rb +0 -266
  47. data/lib/sinatra/test.rb +0 -128
  48. data/lib/sinatra/test/bacon.rb +0 -19
  49. data/lib/sinatra/test/rspec.rb +0 -13
  50. data/lib/sinatra/test/spec.rb +0 -11
  51. data/lib/sinatra/test/unit.rb +0 -13
  52. data/test/test_test.rb +0 -152
@@ -1,2 +0,0 @@
1
- b0rked!
2
- = yield
@@ -1 +0,0 @@
1
- xml.foo "No Layout!"
@@ -1 +0,0 @@
1
- %h1 No Layout!
@@ -1,266 +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
- # The :views_directory, :options, :haml, and :sass options are deprecated.
119
- def render(engine, template, options={}, locals={}, &bk)
120
- if options.key?(:views_directory)
121
- sinatra_warn "The :views_directory option is deprecated; use :views instead."
122
- options[:views] = options.delete(:views_directory)
123
- end
124
- [:options, engine.to_sym].each do |key|
125
- if options.key?(key)
126
- sinatra_warn "Passing :#{key} => {} to #{engine} is deprecated; " +
127
- "merge options directly into hash instead."
128
- options.merge! options.delete(key)
129
- end
130
- end
131
- super(engine, template, options, locals, &bk)
132
- end
133
-
134
- # Throwing halt with a Symbol and the to_result convention are
135
- # deprecated. Override the invoke method to detect those types of return
136
- # values.
137
- def invoke(&block) #:nodoc:
138
- res = super
139
- case
140
- when res.kind_of?(Symbol)
141
- sinatra_warn "Invoking the :#{res} helper by returning a Symbol is deprecated;",
142
- "call the helper directly instead."
143
- @response.body = __send__(res)
144
- when res.respond_to?(:to_result)
145
- sinatra_warn "The to_result convention is deprecated."
146
- @response.body = res.to_result(self)
147
- end
148
- res
149
- end
150
-
151
- def options #:nodoc:
152
- Options.new(self.class)
153
- end
154
-
155
- class Options < Struct.new(:target) #:nodoc:
156
- def method_missing(name, *args, &block)
157
- if target.respond_to?(name)
158
- target.__send__(name, *args, &block)
159
- elsif args.empty? && name.to_s !~ /=$/
160
- sinatra_warn 'accessing undefined options will raise a NameError in Sinatra 1.0'
161
- nil
162
- else
163
- super
164
- end
165
- end
166
- end
167
-
168
- class << self
169
- # Deprecated. Options are stored directly on the class object.
170
- def options
171
- sinatra_warn "The 'options' class method is deprecated; use 'self' instead."
172
- Options.new(self)
173
- end
174
-
175
- # Deprecated. Use: configure
176
- def configures(*args, &block)
177
- sinatra_warn "The 'configures' method is deprecated; use 'configure' instead."
178
- configure(*args, &block)
179
- end
180
-
181
- # Deprecated. Use: set
182
- def default_options
183
- sinatra_warn "Sinatra::Application.default_options is deprecated; use 'set' instead."
184
- fake = lambda { |options| set(options) }
185
- def fake.merge!(options) ; call(options) ; end
186
- fake
187
- end
188
-
189
- # Deprecated. Use: set
190
- def set_option(*args, &block)
191
- sinatra_warn "The 'set_option' method is deprecated; use 'set' instead."
192
- set(*args, &block)
193
- end
194
-
195
- def set_options(*args, &block)
196
- sinatra_warn "The 'set_options' method is deprecated; use 'set' instead."
197
- set(*args, &block)
198
- end
199
-
200
- # Deprecated. Use: set :environment, ENV
201
- def env=(value)
202
- sinatra_warn "The :env option is deprecated; use :environment instead."
203
- set :environment, value
204
- end
205
-
206
- # Deprecated. Use: options.environment
207
- def env
208
- sinatra_warn "The :env option is deprecated; use :environment instead."
209
- environment
210
- end
211
- end
212
-
213
- # Deprecated. Missing messages are no longer delegated to @response.
214
- def method_missing(name, *args, &b) #:nodoc:
215
- if @response.respond_to?(name)
216
- sinatra_warn "The '#{name}' method is deprecated; use 'response.#{name}' instead."
217
- @response.send(name, *args, &b)
218
- else
219
- super
220
- end
221
- end
222
- end
223
-
224
- class << self
225
- # Deprecated. Use: Sinatra::Application
226
- def application
227
- sinatra_warn "Sinatra.application is deprecated; use Sinatra::Application instead."
228
- Sinatra::Application
229
- end
230
-
231
- # Deprecated. Use: Sinatra::Application.reset!
232
- def application=(value)
233
- raise ArgumentError unless value.nil?
234
- sinatra_warn "Setting Sinatra.application to nil is deprecated; create a new instance instead."
235
- Sinatra.class_eval do
236
- remove_const :Application
237
- const_set :Application, Class.new(Sinatra::Default)
238
- end
239
- end
240
-
241
- def build_application
242
- sinatra_warn "Sinatra.build_application is deprecated; use Sinatra::Application instead."
243
- Sinatra::Application
244
- end
245
-
246
- def options
247
- sinatra_warn "Sinatra.options is deprecated; use Sinatra::Application.option_name instead."
248
- Sinatra::Application.options
249
- end
250
-
251
- def port
252
- sinatra_warn "Sinatra.port is deprecated; use Sinatra::Application.port instead."
253
- options.port
254
- end
255
-
256
- def host
257
- sinatra_warn "Sinatra.host is deprecated; use Sinatra::Application.host instead."
258
- options.host
259
- end
260
-
261
- def env
262
- sinatra_warn "Sinatra.env is deprecated; use Sinatra::Application.environment instead."
263
- options.environment
264
- end
265
- end
266
- end
data/lib/sinatra/test.rb DELETED
@@ -1,128 +0,0 @@
1
- require 'sinatra/base'
2
-
3
- warn 'Sinatra::Test is deprecated; use Rack::Test instead.'
4
-
5
- module Sinatra
6
- module Test
7
- include Rack::Utils
8
-
9
- def self.included(base)
10
- Sinatra::Default.set(:environment, :test)
11
- end
12
-
13
- attr_reader :app, :request, :response
14
-
15
- def self.deprecate(framework)
16
- warn <<-EOF
17
- Warning: support for the #{framework} testing framework is deprecated and
18
- will be dropped in Sinatra 1.0. See <http://sinatra.github.com/testing.html>
19
- for more information.
20
- EOF
21
- end
22
-
23
- def make_request(verb, path, body=nil, options={})
24
- @app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application)
25
- fail "@app not set - cannot make request" if @app.nil?
26
-
27
- @request = Rack::MockRequest.new(@app)
28
- options = { :lint => true }.merge(options || {})
29
-
30
- case
31
- when body.respond_to?(:to_hash)
32
- options.merge! body.delete(:env) if body.key?(:env)
33
- options[:input] = param_string(body)
34
- when body.respond_to?(:to_str)
35
- options[:input] = body
36
- when body.nil?
37
- options[:input] = ''
38
- else
39
- raise ArgumentError, "body must be a Hash, String, or nil"
40
- end
41
-
42
- yield @request if block_given?
43
- @response = @request.request(verb, path, rack_options(options))
44
- end
45
-
46
- def get(path, *args, &b) ; make_request('GET', path, *args, &b) ; end
47
- def head(path, *args, &b) ; make_request('HEAD', path, *args, &b) ; end
48
- def post(path, *args, &b) ; make_request('POST', path, *args, &b) ; end
49
- def put(path, *args, &b) ; make_request('PUT', path, *args, &b) ; end
50
- def delete(path, *args, &b) ; make_request('DELETE', path, *args, &b) ; end
51
-
52
- def follow!
53
- make_request 'GET', @response.location
54
- end
55
-
56
- def body ; @response.body ; end
57
- def status ; @response.status ; end
58
-
59
- # Delegate other missing methods to @response.
60
- def method_missing(name, *args, &block)
61
- if @response && @response.respond_to?(name)
62
- @response.send(name, *args, &block)
63
- else
64
- super
65
- end
66
- end
67
-
68
- # Also check @response since we delegate there.
69
- def respond_to?(symbol, include_private=false)
70
- super || (@response && @response.respond_to?(symbol, include_private))
71
- end
72
-
73
- private
74
-
75
- RACK_OPTIONS = {
76
- :accept => 'HTTP_ACCEPT',
77
- :agent => 'HTTP_USER_AGENT',
78
- :host => 'HTTP_HOST',
79
- :session => 'rack.session',
80
- :cookies => 'HTTP_COOKIE',
81
- :content_type => 'CONTENT_TYPE'
82
- }
83
-
84
- def rack_options(opts)
85
- opts.merge(:lint => true).inject({}) do |hash,(key,val)|
86
- key = RACK_OPTIONS[key] || key
87
- hash[key] = val
88
- hash
89
- end
90
- end
91
-
92
- def param_string(value, prefix = nil)
93
- case value
94
- when Array
95
- value.map { |v|
96
- param_string(v, "#{prefix}[]")
97
- } * "&"
98
- when Hash
99
- value.map { |k, v|
100
- param_string(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
101
- } * "&"
102
- else
103
- "#{prefix}=#{escape(value)}"
104
- end
105
- end
106
-
107
- if defined? Sinatra::Compat
108
- # Deprecated. Use: "get" instead of "get_it".
109
- %w(get head post put delete).each do |verb|
110
- eval <<-RUBY, binding, __FILE__, __LINE__
111
- def #{verb}_it(*args, &block)
112
- sinatra_warn "The #{verb}_it method is deprecated; use #{verb} instead."
113
- make_request('#{verb.upcase}', *args, &block)
114
- end
115
- RUBY
116
- end
117
- end
118
- end
119
-
120
- class TestHarness
121
- include Test
122
-
123
- def initialize(app=nil)
124
- @app = app || Sinatra::Application
125
- @app.set(:environment, :test)
126
- end
127
- end
128
- end
@@ -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)
@@ -1,13 +0,0 @@
1
- require 'sinatra/test'
2
- require 'sinatra/test/unit'
3
- require 'spec'
4
- require 'spec/interop/test'
5
-
6
- Sinatra::Test.deprecate('RSpec')
7
-
8
- Sinatra::Default.set(
9
- :environment => :test,
10
- :run => false,
11
- :raise_errors => true,
12
- :logging => false
13
- )
@@ -1,11 +0,0 @@
1
- require 'test/spec'
2
- require 'sinatra/test'
3
- require 'sinatra/test/unit'
4
-
5
- Sinatra::Test.deprecate('test/spec')
6
-
7
- module Sinatra::Test
8
- def should
9
- @response.should
10
- end
11
- end