Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3944

Show
Ignore:
Timestamp:
03/18/06 21:17:14 (3 years ago)
Author:
david
Message:

Removed XML argument style for respond_to, so type.xml(object.to_xml) no longer works -- it wasnt worth the exception

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/mime_responds.rb

    r3919 r3944  
    1919        :html    => 'Proc.new { render }', 
    2020        :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" }' 
    2322      } 
    2423       
     
    3029      end 
    3130 
    32       def custom(mime_type, *args, &block) 
     31      def custom(mime_type, &block) 
    3332        mime_type = mime_type.is_a?(Mime::Type) ? mime_type : Mime::Type.lookup(mime_type.to_s) 
    3433         
     
    3837          @responses[mime_type] = block 
    3938        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) 
    4640        end 
    4741      end 
     
    4943      for mime_type in %w( all html js xml rss atom yaml ) 
    5044        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) 
    5347          end 
    5448        EOT 
  • trunk/actionpack/lib/action_view/base.rb

    r3884 r3944  
    219219    # is made available as local variables. 
    220220    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? 
    222222 
    223223      if use_full_path 
  • trunk/actionpack/test/controller/layout_test.rb

    r3423 r3944  
    7171    assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body 
    7272  end 
    73  
    7473end 
  • trunk/actionpack/test/controller/mime_responds_test.rb

    r3934 r3944  
    22 
    33class RespondToController < ActionController::Base 
     4  layout :set_layout 
     5 
    46  def html_xml_or_rss 
    57    respond_to do |type| 
     
    4547  end 
    4648   
    47   def using_argument_defaults 
    48     person_in_xml = { :name => "David" }.to_xml(:root => "person") 
    49     respond_to do |type| 
    50       type.html 
    51       type.xml(person_in_xml) 
    52     end 
    53   end 
    54  
    5549  def made_for_content_type 
    5650    respond_to do |type| 
     
    7670  end 
    7771 
     72  def all_types_with_layout 
     73    respond_to do |type| 
     74      type.html 
     75      type.js 
     76    end 
     77  end 
     78 
    7879  def rescue_action(e) 
    7980    raise 
    8081  end 
     82   
     83  protected 
     84    def set_layout 
     85      if action_name == "all_types_with_layout" 
     86        "standard" 
     87      end 
     88    end 
    8189end 
    8290 
     
    174182  end 
    175183   
    176   def test_using_argument_defaults 
    177     @request.env["HTTP_ACCEPT"] = "application/xml" 
    178     get :using_argument_defaults 
    179     assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n  <name>David</name>\n</person>\n", @response.body 
    180   end 
    181    
    182184  def test_with_content_type 
    183185    @request.env["CONTENT_TYPE"] = "application/atom+xml" 
     
    196198 
    197199    @request.env["HTTP_ACCEPT"] = "application/x-xml" 
    198     get :using_argument_default
    199     assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n  <name>David</name>\n</person>\n", @response.body 
     200    get :html_xml_or_rs
     201    assert_equal "XML", @response.body 
    200202  end 
    201203   
     
    235237    assert_equal 'Either JS or XML', @response.body 
    236238  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 
    237249end