diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index d492b6c258c9da6c9c99d3f7d1534363513e0aa5..4dad2c96d2e054c315f984ea4bc9dd050e521a06 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -18,8 +18,7 @@ class Responder #:nodoc: DEFAULT_BLOCKS = { :html => 'Proc.new { render }', :js => 'Proc.new { render :action => "#{action_name}.rjs" }', - :xml => 'Proc.new { render :action => "#{action_name}.rxml" }', - :xml_arg => 'Proc.new { render :xml => __mime_responder_arg__ }' + :xml => 'Proc.new { render :action => "#{action_name}.rxml" }' } def initialize(block_binding) @@ -29,7 +28,7 @@ def initialize(block_binding) @responses = {} end - def custom(mime_type, *args, &block) + def custom(mime_type, &block) mime_type = mime_type.is_a?(Mime::Type) ? mime_type : Mime::Type.lookup(mime_type.to_s) @order << mime_type @@ -37,19 +36,14 @@ def custom(mime_type, *args, &block) if block_given? @responses[mime_type] = block else - if argument = args.first - eval("__mime_responder_arg__ = #{argument.is_a?(String) ? argument.inspect : argument}", @block_binding) - @responses[mime_type] = eval(DEFAULT_BLOCKS[(mime_type.to_sym.to_s + "_arg").to_sym], @block_binding) - else - @responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding) - end + @responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding) end end for mime_type in %w( all html js xml rss atom yaml ) eval <<-EOT - def #{mime_type}(argument = nil, &block) - custom(Mime::#{mime_type.upcase}, argument, &block) + def #{mime_type}(&block) + custom(Mime::#{mime_type.upcase}, &block) end EOT end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index b118ee104239c506f7c136490e65ec2e22349e99..dff5a365d46b88c644fcc36c349c50d9083385d5 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -218,7 +218,7 @@ def initialize(base_path = nil, assigns_for_first_render = {}, controller = nil) # it's relative to the template_root, otherwise it's absolute. The hash in local_assigns # is made available as local variables. def render_file(template_path, use_full_path = true, local_assigns = {}) - @first_render = template_path if @first_render.nil? + @first_render = template_path if @first_render.nil? if use_full_path template_path_without_extension, template_extension = path_and_extension(template_path) diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index cffd4d388e585de55a9d11ffb60bf6e70d16fb3a..c7db19ccc984153ed9c682488899f335f2daad22 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -70,5 +70,4 @@ def test_namespaced_controllers_auto_detect_layouts assert_equal 'layouts/controller_name_space/nested', @controller.active_layout assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body end - end \ No newline at end of file diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 06addad2ead6bccd382b18b54c255b1ecd9f92f6..6fe14bf65bf32894af0e31bfa84e98e838b93176 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -1,6 +1,8 @@ require File.dirname(__FILE__) + '/../abstract_unit' class RespondToController < ActionController::Base + layout :set_layout + def html_xml_or_rss respond_to do |type| type.html { render :text => "HTML" } @@ -44,14 +46,6 @@ def using_defaults_with_type_list respond_to(:html, :js, :xml) end - def using_argument_defaults - person_in_xml = { :name => "David" }.to_xml(:root => "person") - respond_to do |type| - type.html - type.xml(person_in_xml) - end - end - def made_for_content_type respond_to do |type| type.rss { render :text => "RSS" } @@ -75,9 +69,23 @@ def handle_any end end + def all_types_with_layout + respond_to do |type| + type.html + type.js + end + end + def rescue_action(e) raise end + + protected + def set_layout + if action_name == "all_types_with_layout" + "standard" + end + end end RespondToController.template_root = File.dirname(__FILE__) + "/../fixtures/" @@ -173,12 +181,6 @@ def test_using_defaults_with_type_list assert_equal "

Hello world!

\n", @response.body end - def test_using_argument_defaults - @request.env["HTTP_ACCEPT"] = "application/xml" - get :using_argument_defaults - assert_equal "\n\n David\n\n", @response.body - end - def test_with_content_type @request.env["CONTENT_TYPE"] = "application/atom+xml" get :made_for_content_type @@ -195,8 +197,8 @@ def test_synonyms assert_equal 'JS', @response.body @request.env["HTTP_ACCEPT"] = "application/x-xml" - get :using_argument_defaults - assert_equal "\n\n David\n\n", @response.body + get :html_xml_or_rss + assert_equal "XML", @response.body end def test_custom_types @@ -234,4 +236,14 @@ def test_handle_any get :handle_any assert_equal 'Either JS or XML', @response.body end + + def test_all_types_with_layout + @request.env["HTTP_ACCEPT"] = "text/javascript" + get :all_types_with_layout + assert_equal 'RJS for all_types_with_layout', @response.body + + @request.env["HTTP_ACCEPT"] = "text/html" + get :all_types_with_layout + assert_equal 'HTML for all_types_with_layout', @response.body + end end \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml b/actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..84a84049f8b09f83b5a6394f650eaec617173d47 --- /dev/null +++ b/actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml @@ -0,0 +1 @@ +HTML for all_types_with_layout \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/all_types_with_layout.rjs b/actionpack/test/fixtures/respond_to/all_types_with_layout.rjs new file mode 100644 index 0000000000000000000000000000000000000000..b7aec7c50504764f22804721f1149b717f42ebbe --- /dev/null +++ b/actionpack/test/fixtures/respond_to/all_types_with_layout.rjs @@ -0,0 +1 @@ +page << "RJS for all_types_with_layout" \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/layouts/standard.rhtml b/actionpack/test/fixtures/respond_to/layouts/standard.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..fcb28ec7553a4100f0d7d95ce0116e729074d308 --- /dev/null +++ b/actionpack/test/fixtures/respond_to/layouts/standard.rhtml @@ -0,0 +1 @@ +<%= @content_for_layout %> \ No newline at end of file