Browse files

Depend on Rack 0.9.0 (up from 0.4.0)

* Remove the Rack::MethodOverride class from sinatra since it's
  included with rack core now.

* Update mime type handling to work with Rack 0.9.0's new
  Rack::Mime module.
  • Loading branch information...
1 parent 54b9ecf commit 123cc5b5acc1ee99366ef2e1e5d4ca7853a7b461 @rtomayko rtomayko committed Jan 6, 2009
Showing with 18 additions and 40 deletions.
  1. +3 −11 lib/sinatra/base.rb
  2. +10 −0 lib/sinatra/compat.rb
  3. +2 −5 lib/sinatra/main.rb
  4. +0 −21 lib/sinatra/rack/methodoverride.rb
  5. +1 −1 sinatra.gemspec
  6. +2 −2 test/helpers_test.rb
View
14 lib/sinatra/base.rb
@@ -1,7 +1,7 @@
+require 'time'
require 'uri'
require 'rack'
require 'rack/builder'
-require 'sinatra/rack/methodoverride'
module Sinatra
VERSION = '0.9.0'
@@ -89,7 +89,8 @@ def session
# Look up a media type by file extension in Rack's mime registry.
def media_type(type)
return type if type.nil? || type.to_s.include?('/')
- Rack::File::MIME_TYPES[type.to_s.sub(/^\./, '')]
+ type = ".#{type}" unless type.to_s[0] == ?.
+ Rack::Mime.mime_type(type, nil)
end
# Set the Content-Type of the response body given a media type or file
@@ -771,12 +772,3 @@ def self.new(base=Base, options={}, &block)
base
end
end
-
-# Make Rack 0.5.0 backward compatibile with 0.4.0 mime types
-require 'rack/file'
-class Rack::File
- unless defined? MIME_TYPES
- MIME_TYPES = Hash.new {|hash,key|
- Rack::Mime::MIME_TYPES[".#{key}"] }
- end
-end
View
10 lib/sinatra/compat.rb
@@ -11,6 +11,16 @@
puts "Using Evented Mongrel"
end
+# Deprecated. Make Rack 0.9.0 backward compatibile with 0.4.0
+# mime types
+require 'rack/file'
+class Rack::File
+ unless defined? MIME_TYPES
+ MIME_TYPES = Hash.new {|hash,key|
+ Rack::Mime::MIME_TYPES[".#{key}"] }
+ end
+end
+
# Deprecated. Rack::Utils will not extend itself in the future. Sinatra::Base
# includes Rack::Utils, however.
module Rack::Utils ; extend self ; end
View
7 lib/sinatra/main.rb
@@ -38,14 +38,11 @@ def helpers(&block)
end
def mime(ext, type)
- Rack::File::MIME_TYPES[ext.to_s] = type
+ ext = ".#{ext}" unless ext.to_s[0] == ?.
+ Rack::Mime::MIME_TYPES[ext.to_s] = type
end
at_exit do
raise $! if $!
Sinatra::Application.run! if Sinatra::Application.run?
end
-
-mime :xml, 'application/xml'
-mime :js, 'application/javascript'
-mime :png, 'image/png'
View
21 lib/sinatra/rack/methodoverride.rb
@@ -1,21 +0,0 @@
-module Rack
- class MethodOverride
- HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
-
- def initialize(app)
- @app = app
- end
-
- def call(env)
- if env["REQUEST_METHOD"] == "POST"
- req = Request.new(env)
- method = req.POST["_method"].to_s.upcase
- if HTTP_METHODS.include?(method)
- env["REQUEST_METHOD"] = method
- end
- end
-
- @app.call(env)
- end
- end
-end
View
2 sinatra.gemspec
@@ -96,7 +96,7 @@ Gem::Specification.new do |s|
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
s.extra_rdoc_files = %w[README.rdoc LICENSE]
- s.add_dependency 'rack', '>= 0.4.0'
+ s.add_dependency 'rack', '>= 0.9.0'
s.has_rdoc = true
s.homepage = "http://sinatra.rubyforge.org"
View
4 test/helpers_test.rb
@@ -162,7 +162,7 @@ class Test::Unit::TestCase
describe '#media_type' do
include Sinatra::Helpers
it "looks up media types in Rack's MIME registry" do
- Rack::File::MIME_TYPES['foo'] = 'application/foo'
+ Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
media_type('foo').should.equal 'application/foo'
media_type('.foo').should.equal 'application/foo'
media_type(:foo).should.equal 'application/foo'
@@ -207,7 +207,7 @@ class Test::Unit::TestCase
end
it "looks up symbols in Rack's mime types dictionary" do
- Rack::File::MIME_TYPES['foo'] = 'application/foo'
+ Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
mock_app {
get '/foo.xml' do
content_type :foo

0 comments on commit 123cc5b

Please sign in to comment.