diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-11 01:23:29 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-11 01:23:29 +0000 |
commit | 1c16649b4895012eac76f3a7f22f3382b0034a97 (patch) | |
tree | 6674f67a9ea89529b02164a08e076e51b82a1bf1 /actionpack/lib/action_controller/mime_type.rb | |
parent | 8152695b809aa47177ab5d5db43d93d8f55ee52a (diff) | |
download | rails-1c16649b4895012eac76f3a7f22f3382b0034a97.tar.gz rails-1c16649b4895012eac76f3a7f22f3382b0034a97.tar.bz2 rails-1c16649b4895012eac76f3a7f22f3382b0034a97.zip |
Added better support for using the same actions to output for different sources depending on the Accept header [DHH] Added Base#render(:xml => xml) that works just like Base#render(:text => text), but sets the content-type to text/xml and the charset to UTF-8 [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3838 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/mime_type.rb')
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb new file mode 100644 index 0000000000..0ab0221007 --- /dev/null +++ b/actionpack/lib/action_controller/mime_type.rb @@ -0,0 +1,44 @@ +module Mime + class Type < String + def initialize(string, part_of_all = true) + @part_of_all = part_of_all + super(string) + end + + def to_sym + SYMBOLIZED_MIME_TYPES[self] ? SYMBOLIZED_MIME_TYPES[self] : to_sym + end + + def ===(list) + if list.is_a?(Array) + list.include?(self) + else + super + end + end + end + + SYMBOLIZED_MIME_TYPES = { + "" => :unspecified, + "*/*" => :all, + "text/html" => :html, + "application/javascript" => :js, + "application/x-javascript" => :js, + "text/javascript" => :js, + "text/xml" => :xml, + "application/xml" => :xml, + "application/rss+xml" => :rss, + "application/rss+atom" => :atom, + "application/x-xml" => :xml, + "application/x-yaml" => :yaml + } + + ALL = Type.new "*/*" + HTML = Type.new "text/html" + JS = Type.new "text/javascript" + JAVASCRIPT = Type.new "text/javascript" + XML = Type.new "application/xml" + RSS = Type.new "application/rss+xml" + ATOM = Type.new "application/rss+atom" + YAML = Type.new "application/x-yaml" +end
\ No newline at end of file |