sinatra 0.9.6 → 1.0.a

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.

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