diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-02 04:29:34 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-02 04:29:34 +0000 |
commit | 5e998d1ea07f227f436c64b2ee748ec18d6f5456 (patch) | |
tree | d4966152b4971ff53743c45fc9df7cbfdbcdc52c /actionpack/lib/action_controller | |
parent | 5240d7a84b2c4919cbc9f6d0d95c45b6b75227ae (diff) | |
download | rails-5e998d1ea07f227f436c64b2ee748ec18d6f5456.tar.gz rails-5e998d1ea07f227f436c64b2ee748ec18d6f5456.tar.bz2 rails-5e998d1ea07f227f436c64b2ee748ec18d6f5456.zip |
Make new mime types first class [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4407 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/mime_responds.rb | 10 | ||||
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 4 |
2 files changed, 6 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index e1e6790381..e297cf8b07 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -94,7 +94,7 @@ module ActionController #:nodoc: # and accept Rails' defaults, life will be much easier. def respond_to(*types, &block) raise ArgumentError, "respond_to takes either types or a block, never bot" unless types.any? ^ block - block ||= lambda { |responder| types.each { |type| responder.send(type) } } + block ||= lambda { |responder| types.each { |type| responder.known(type) } } responder = Responder.new(block.binding) block.call(responder) responder.respond @@ -132,12 +132,8 @@ module ActionController #:nodoc: end end - for mime_type in %w( all html js xml rss atom yaml ) - eval <<-EOT - def #{mime_type}(&block) - custom(Mime::#{mime_type.upcase}, &block) - end - EOT + def known(mime_type_extension, &block) + custom(Mime.const_get(mime_type_extension.to_s.upcase), &block) end def any(*args, &block) diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index a2233477bd..7c1448029d 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -33,7 +33,8 @@ module Mime def register(string, symbol, synonyms = []) Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, synonyms) - LOOKUP[string] = Mime.send :const_get, symbol.to_s.upcase + SET << Mime.send(:const_get, symbol.to_s.upcase) + LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last end def parse(accept_header) @@ -126,6 +127,7 @@ module Mime ATOM = Type.new "application/atom+xml", :atom YAML = Type.new "application/x-yaml", :yaml, %w( text/yaml ) + SET = [ ALL, TEXT, HTML, JS, ICS, XML, RSS, ATOM, YAML ] LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k == "" } |