diff options
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 16 | ||||
-rw-r--r-- | actionpack/test/controller/mime_type_test.rb | 6 |
3 files changed, 20 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 23da55ca6b..5c3a75755c 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added Mime::Type.register(string, symbol, synonyms = []) for adding new custom mime types [DHH]. Example: Mime::Type.register("image/gif", :gif) + * Added support for Mime objects in render :content_type option [DHH]. Example: render :text => some_atom, :content_type => Mime::ATOM * Add :status option to send_data and send_file. Defaults to '200 OK'. #5243 [Manfred Stienstra <m.stienstra@fngtps.com>] 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 diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb index aa1d4459ee..436251b0f9 100644 --- a/actionpack/test/controller/mime_type_test.rb +++ b/actionpack/test/controller/mime_type_test.rb @@ -21,4 +21,10 @@ class MimeTypeTest < Test::Unit::TestCase expect = [Mime::HTML, Mime::XML, Mime::PNG, Mime::PLAIN, Mime::YAML, Mime::ALL] assert_equal expect, Mime::Type.parse(accept) end + + def test_custom_type + Mime::Type.register("image/gif", :gif) + assert_nothing_raised { Mime::GIF } + Mime.send :remove_const, :GIF + end end
\ No newline at end of file |