diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-02 04:11:56 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-02 04:11:56 +0000 |
commit | 984aa7eeb9da2860e6cd8954a93657c774eff207 (patch) | |
tree | 3d16110de8b6a3762a8fbc465c03601cc240cea0 /actionpack/lib/action_controller | |
parent | 5c30352328f8a0223746139e024b6bea7b3d36c0 (diff) | |
download | rails-984aa7eeb9da2860e6cd8954a93657c774eff207.tar.gz rails-984aa7eeb9da2860e6cd8954a93657c774eff207.tar.bz2 rails-984aa7eeb9da2860e6cd8954a93657c774eff207.zip |
Added Mime::Type.register(string, symbol, synonyms = []) for adding new custom mime types [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4405 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index f4d80c26c0..6ed72971cd 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -31,6 +31,11 @@ module Mime LOOKUP[string] end + 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 + end + def parse(accept_header) # keep track of creation order to keep the subsequent sort stable index = 0 @@ -114,6 +119,7 @@ module Mime ALL = Type.new "*/*", :all HTML = Type.new "text/html", :html, %w( application/xhtml+xml ) JS = Type.new "text/javascript", :js, %w( application/javascript application/x-javascript ) + ICS = Type.new "text/calendar", :ics XML = Type.new "application/xml", :xml, %w( text/xml application/x-xml ) RSS = Type.new "application/rss+xml", :rss ATOM = Type.new "application/atom+xml", :atom @@ -127,14 +133,16 @@ module Mime LOOKUP["text/html"] = HTML LOOKUP["application/xhtml+xml"] = HTML - LOOKUP["application/xml"] = XML - LOOKUP["text/xml"] = XML - LOOKUP["application/x-xml"] = XML - LOOKUP["text/javascript"] = JS LOOKUP["application/javascript"] = JS LOOKUP["application/x-javascript"] = JS + LOOKUP["text/calendar"] = ICS + + LOOKUP["application/xml"] = XML + LOOKUP["text/xml"] = XML + LOOKUP["application/x-xml"] = XML + LOOKUP["text/yaml"] = YAML LOOKUP["application/x-yaml"] = YAML |