From 984aa7eeb9da2860e6cd8954a93657c774eff207 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 2 Jun 2006 04:11:56 +0000 Subject: 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 --- actionpack/lib/action_controller/mime_type.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller') 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 -- cgit v1.2.3