Changeset 5129
- Timestamp:
- 09/17/06 16:20:32 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (5 diffs)
- trunk/actionpack/lib/action_controller/caching.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/rescue.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/response.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/base.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/action_pack_assertions_test.rb (modified) (3 diffs)
- trunk/actionpack/test/controller/content_type_test.rb (added)
- trunk/actionpack/test/controller/new_render_test.rb (modified) (3 diffs)
- trunk/actionpack/test/fixtures/content_type (added)
- trunk/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml (added)
- trunk/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r5128 r5129 1 1 *SVN* 2 3 * Added utf-8 as the default charset for all renders. You can change this default using ActionController::Base.default_charset=(encoding) [DHH] 4 5 * Added proper getters and setters for content type and charset [DHH]. Example of what we used to do: 6 7 response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" 8 9 ...now: 10 11 response.content_type = Mime::ATOM 12 response.charset = "utf-8" 2 13 3 14 * Updated prototype.js to 1.5.0_rc1 with latest fixes. [Rick Olson] trunk/actionpack/lib/action_controller/base.rb
r5126 r5129 273 273 cattr_accessor :param_parsers 274 274 275 # Controls the default charset for all renders. 276 @@default_charset = "utf-8" 277 cattr_accessor :default_charset 278 275 279 # Template root determines the base from which template references will be made. So a call to render("test/template") 276 280 # will be converted to "#{template_root}/test/template.rhtml". … … 421 425 send(method, *arguments) 422 426 427 assign_default_content_type_and_charset 423 428 response 424 429 ensure … … 704 709 705 710 if content_type = options[:content_type] 706 headers["Content-Type"]= content_type.to_s711 response.content_type = content_type.to_s 707 712 end 708 713 … … 794 799 795 800 def render_javascript(javascript, status = nil) #:nodoc: 796 response. headers['Content-Type'] = 'text/javascript; charset=UTF-8'801 response.content_type = Mime::JS 797 802 render_text(javascript, status) 798 803 end 799 804 800 805 def render_xml(xml, status = nil) #:nodoc: 801 response. headers['Content-Type'] = 'application/xml'806 response.content_type = Mime::XML 802 807 render_text(xml, status) 803 808 end … … 1035 1040 end 1036 1041 1042 def assign_default_content_type_and_charset 1043 response.content_type ||= Mime::HTML 1044 response.charset ||= self.class.default_charset 1045 end 1046 1037 1047 def action_methods 1038 1048 self.class.action_methods trunk/actionpack/lib/action_controller/caching.rb
r4898 r5129 211 211 if extention = action_cache_path.extension 212 212 content_type = Mime::EXTENSION_LOOKUP[extention] 213 action_cache_path.controller. headers['Content-Type']= content_type.to_s213 action_cache_path.controller.content_type = content_type.to_s 214 214 end 215 215 end trunk/actionpack/lib/action_controller/rescue.rb
r4955 r5129 72 72 @template.instance_variable_set("@contents", @template.render_file(template_path_for_local_rescue(exception), false)) 73 73 74 @headers["Content-Type"] = "text/html"74 response.content_type = Mime::HTML 75 75 render_file(rescues_path("layout"), response_code_for_rescue(exception)) 76 76 end trunk/actionpack/lib/action_controller/response.rb
r4346 r5129 6 6 def initialize 7 7 @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], [] 8 end 9 10 def content_type=(mime_type) 11 @headers["Content-Type"] = charset ? "#{mime_type}; charset=#{charset}" : mime_type 12 end 13 14 def content_type 15 content_type = String(@headers["Content-Type"]).split(";")[0] 16 content_type.blank? ? nil : content_type 17 end 18 19 def charset=(encoding) 20 @headers["Content-Type"] = "#{content_type || "text/html"}; charset=#{encoding}" 21 end 22 23 def charset 24 charset = String(@headers["Content-Type"]).split(";")[1] 25 charset.blank? ? nil : charset.strip.split("=")[1] 8 26 end 9 27 trunk/actionpack/lib/action_view/base.rb
r5095 r5129 2 2 3 3 module ActionView #:nodoc: 4 5 4 class ActionViewError < StandardError #:nodoc: 6 5 end … … 442 441 body = case extension.to_sym 443 442 when :rxml 443 "@controller.response.content_type ||= 'application/xml'\n" + 444 444 "xml = Builder::XmlMarkup.new(:indent => 2)\n" + 445 "@controller.headers['Content-Type'] ||= 'application/xml'\n" +446 445 template 447 446 when :rjs 448 "@controller. headers['Content-Type']||= 'text/javascript'\n" +447 "@controller.response.content_type ||= 'text/javascript'\n" + 449 448 "update_page do |page|\n#{template}\nend" 450 449 end trunk/actionpack/test/controller/action_pack_assertions_test.rb
r4976 r5129 569 569 def test_rendering_xml_sets_content_type 570 570 assert_deprecated(/render/) { process :hello_xml_world } 571 assert_equal('application/xml ', @controller.headers['Content-Type'])571 assert_equal('application/xml; charset=utf-8', @controller.headers['Content-Type']) 572 572 end 573 573 … … 575 575 @response.headers['Content-Type'] = 'application/pdf' 576 576 assert_deprecated(/render/) { process :hello_xml_world } 577 assert_equal('application/pdf ', @controller.headers['Content-Type'])577 assert_equal('application/pdf; charset=utf-8', @controller.headers['Content-Type']) 578 578 end 579 579 … … 581 581 def test_render_text_with_custom_content_type 582 582 get :render_text_with_custom_content_type 583 assert_equal 'application/rss+xml ', @response.headers['Content-Type']583 assert_equal 'application/rss+xml; charset=utf-8', @response.headers['Content-Type'] 584 584 end 585 585 end trunk/actionpack/test/controller/new_render_test.rb
r4974 r5129 262 262 def yield_content_for 263 263 render :action => "content_for", :layout => "yield" 264 end 265 266 def render_content_type_from_body 267 response.content_type = Mime::RSS 268 render :text => "hello world!" 264 269 end 265 270 … … 573 578 get :update_page 574 579 assert_template nil 575 assert_equal 'text/javascript; charset= UTF-8', @response.headers['Content-Type']580 assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type'] 576 581 assert_equal 2, @response.body.split($/).length 577 582 end … … 580 585 get :update_page_with_instance_variables 581 586 assert_template nil 582 assert_equal 'text/javascript; charset= UTF-8', @response.headers['Content-Type']587 assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type'] 583 588 assert_match /balance/, @response.body 584 589 assert_match /\$37/, @response.body