Changeset 3944
- Timestamp:
- 03/18/06 21:17:14 (3 years ago)
- Files:
-
- trunk/actionpack/lib/action_controller/mime_responds.rb (modified) (4 diffs)
- trunk/actionpack/lib/action_view/base.rb (modified) (1 diff)
- trunk/actionpack/test/controller/layout_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/mime_responds_test.rb (modified) (6 diffs)
- trunk/actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml (added)
- trunk/actionpack/test/fixtures/respond_to/all_types_with_layout.rjs (added)
- trunk/actionpack/test/fixtures/respond_to/layouts (added)
- trunk/actionpack/test/fixtures/respond_to/layouts/standard.rhtml (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/mime_responds.rb
r3919 r3944 19 19 :html => 'Proc.new { render }', 20 20 :js => 'Proc.new { render :action => "#{action_name}.rjs" }', 21 :xml => 'Proc.new { render :action => "#{action_name}.rxml" }', 22 :xml_arg => 'Proc.new { render :xml => __mime_responder_arg__ }' 21 :xml => 'Proc.new { render :action => "#{action_name}.rxml" }' 23 22 } 24 23 … … 30 29 end 31 30 32 def custom(mime_type, *args,&block)31 def custom(mime_type, &block) 33 32 mime_type = mime_type.is_a?(Mime::Type) ? mime_type : Mime::Type.lookup(mime_type.to_s) 34 33 … … 38 37 @responses[mime_type] = block 39 38 else 40 if argument = args.first 41 eval("__mime_responder_arg__ = #{argument.is_a?(String) ? argument.inspect : argument}", @block_binding) 42 @responses[mime_type] = eval(DEFAULT_BLOCKS[(mime_type.to_sym.to_s + "_arg").to_sym], @block_binding) 43 else 44 @responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding) 45 end 39 @responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding) 46 40 end 47 41 end … … 49 43 for mime_type in %w( all html js xml rss atom yaml ) 50 44 eval <<-EOT 51 def #{mime_type}( argument = nil,&block)52 custom(Mime::#{mime_type.upcase}, argument,&block)45 def #{mime_type}(&block) 46 custom(Mime::#{mime_type.upcase}, &block) 53 47 end 54 48 EOT trunk/actionpack/lib/action_view/base.rb
r3884 r3944 219 219 # is made available as local variables. 220 220 def render_file(template_path, use_full_path = true, local_assigns = {}) 221 @first_render = template_path if @first_render.nil?221 @first_render = template_path if @first_render.nil? 222 222 223 223 if use_full_path trunk/actionpack/test/controller/layout_test.rb
r3423 r3944 71 71 assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body 72 72 end 73 74 73 end trunk/actionpack/test/controller/mime_responds_test.rb
r3934 r3944 2 2 3 3 class RespondToController < ActionController::Base 4 layout :set_layout 5 4 6 def html_xml_or_rss 5 7 respond_to do |type| … … 45 47 end 46 48 47 def using_argument_defaults48 person_in_xml = { :name => "David" }.to_xml(:root => "person")49 respond_to do |type|50 type.html51 type.xml(person_in_xml)52 end53 end54 55 49 def made_for_content_type 56 50 respond_to do |type| … … 76 70 end 77 71 72 def all_types_with_layout 73 respond_to do |type| 74 type.html 75 type.js 76 end 77 end 78 78 79 def rescue_action(e) 79 80 raise 80 81 end 82 83 protected 84 def set_layout 85 if action_name == "all_types_with_layout" 86 "standard" 87 end 88 end 81 89 end 82 90 … … 174 182 end 175 183 176 def test_using_argument_defaults177 @request.env["HTTP_ACCEPT"] = "application/xml"178 get :using_argument_defaults179 assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n <name>David</name>\n</person>\n", @response.body180 end181 182 184 def test_with_content_type 183 185 @request.env["CONTENT_TYPE"] = "application/atom+xml" … … 196 198 197 199 @request.env["HTTP_ACCEPT"] = "application/x-xml" 198 get : using_argument_defaults199 assert_equal " <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n <name>David</name>\n</person>\n", @response.body200 get :html_xml_or_rss 201 assert_equal "XML", @response.body 200 202 end 201 203 … … 235 237 assert_equal 'Either JS or XML', @response.body 236 238 end 239 240 def test_all_types_with_layout 241 @request.env["HTTP_ACCEPT"] = "text/javascript" 242 get :all_types_with_layout 243 assert_equal 'RJS for all_types_with_layout', @response.body 244 245 @request.env["HTTP_ACCEPT"] = "text/html" 246 get :all_types_with_layout 247 assert_equal '<html>HTML for all_types_with_layout</html>', @response.body 248 end 237 249 end