aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/mime_type.rb77
-rw-r--r--actionpack/lib/action_controller/mime_types.rb10
2 files changed, 22 insertions, 65 deletions
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb
index 81b84f7672..e57339b3aa 100644
--- a/actionpack/lib/action_controller/mime_type.rb
+++ b/actionpack/lib/action_controller/mime_type.rb
@@ -1,4 +1,8 @@
module Mime
+ SET = []
+ EXTENSION_LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k == "" }
+ LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k == "" }
+
# Encapsulates the notion of a mime type. Can be used at render time, for example, with:
#
# class PostsController < ActionController::Base
@@ -44,10 +48,13 @@ module Mime
LOOKUP[string]
end
- def register(string, symbol, synonyms = [])
- Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, synonyms)
+ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [])
+ Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms)
+
SET << Mime.send(:const_get, symbol.to_s.upcase)
- LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last
+
+ ([string] + mime_type_synonyms).each { |string| LOOKUP[string] = SET.last }
+ ([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last }
end
def parse(accept_header)
@@ -129,66 +136,6 @@ module Mime
(@synonyms + [ self ]).any? { |synonym| synonym.to_s == mime_type.to_s } if mime_type
end
end
+end
- ALL = Type.new "*/*", :all
- TEXT = Type.new "text/plain", :text
- 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
- CSV = Type.new "text/csv", :csv
- 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
- YAML = Type.new "application/x-yaml", :yaml, %w( text/yaml )
-
- SET = [ ALL, TEXT, HTML, JS, ICS, XML, RSS, ATOM, YAML, CSV ]
-
- LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k == "" }
-
- LOOKUP["*/*"] = ALL
-
- LOOKUP["text/plain"] = TEXT
-
- LOOKUP["text/html"] = HTML
- LOOKUP["application/xhtml+xml"] = HTML
-
- LOOKUP["text/javascript"] = JS
- LOOKUP["application/javascript"] = JS
- LOOKUP["application/x-javascript"] = JS
-
- LOOKUP["text/calendar"] = ICS
-
- LOOKUP["text/csv"] = CSV
-
- LOOKUP["application/xml"] = XML
- LOOKUP["text/xml"] = XML
- LOOKUP["application/x-xml"] = XML
-
- LOOKUP["text/yaml"] = YAML
- LOOKUP["application/x-yaml"] = YAML
-
- LOOKUP["application/rss+xml"] = RSS
- LOOKUP["application/atom+xml"] = ATOM
-
-
- EXTENSION_LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k == "" }
-
- EXTENSION_LOOKUP["html"] = HTML
- EXTENSION_LOOKUP["xhtml"] = HTML
-
- EXTENSION_LOOKUP["txt"] = TEXT
-
- EXTENSION_LOOKUP["xml"] = XML
-
- EXTENSION_LOOKUP["js"] = JS
-
- EXTENSION_LOOKUP["ics"] = ICS
-
- EXTENSION_LOOKUP["csv"] = CSV
-
- EXTENSION_LOOKUP["yml"] = YAML
- EXTENSION_LOOKUP["yaml"] = YAML
-
- EXTENSION_LOOKUP["rss"] = RSS
- EXTENSION_LOOKUP["atom"] = ATOM
-end \ No newline at end of file
+require File.dirname(__FILE__) + "/mime_types" \ No newline at end of file
diff --git a/actionpack/lib/action_controller/mime_types.rb b/actionpack/lib/action_controller/mime_types.rb
new file mode 100644
index 0000000000..d968344b26
--- /dev/null
+++ b/actionpack/lib/action_controller/mime_types.rb
@@ -0,0 +1,10 @@
+Mime::Type.register "*/*", :all
+Mime::Type.register "text/plain", :text
+Mime::Type.register "text/html", :html, %w( application/xhtml+xml ), %w( xhtml )
+Mime::Type.register "text/javascript", :js, %w( application/javascript application/x-javascript )
+Mime::Type.register "text/calendar", :ics
+Mime::Type.register "text/csv", :csv
+Mime::Type.register "application/xml", :xml, %w( text/xml application/x-xml )
+Mime::Type.register "application/rss+xml", :rss
+Mime::Type.register "application/atom+xml", :atom
+Mime::Type.register "application/x-yaml", :yaml, %w( text/yaml ) \ No newline at end of file