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

Changeset 6403

Show
Ignore:
Timestamp:
03/13/07 04:46:12 (1 year ago)
Author:
bitsweat
Message:

Deprecation: remove toplevel components directory and uses_component_template_root.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6402 r6403  
    11*SVN* 
    22 
    3 * Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. [Jeremy Kemper] 
     3* Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. Remove uses_component_template_root for toplevel components directory. [Jeremy Kemper] 
    44 
    55* Consistent public/protected/private visibility for chained methods.  #7813 [Dan Manges] 
  • trunk/actionpack/lib/action_controller/components.rb

    r6125 r6403  
    1818  # 
    1919  # The same can be done in a view to do a partial rendering: 
    20   #  
    21   #   Let's see a greeting:  
     20  # 
     21  #   Let's see a greeting: 
    2222  #   <%= render_component :controller => "greeter", :action => "hello_world" %> 
    2323  # 
    2424  # It is also possible to specify the controller as a class constant, bypassing the inflector 
    2525  # code to compute the controller class at runtime: 
    26   #  
     26  # 
    2727  # <%= render_component :controller => GreeterController, :action => "hello_world" %> 
    2828  # 
     
    3131  # Components should be used with care. They're significantly slower than simply splitting reusable parts into partials and 
    3232  # conceptually more complicated. Don't use components as a way of separating concerns inside a single application. Instead, 
    33   # reserve components to those rare cases where you truly have reusable view and controller elements that can be employed  
     33  # reserve components to those rare cases where you truly have reusable view and controller elements that can be employed 
    3434  # across many applications at once. 
    3535  # 
     
    4141 
    4242      base.helper do 
    43         def render_component(options)  
     43        def render_component(options) 
    4444          @controller.send(:render_component_as_string, options) 
    4545        end 
    4646      end 
    47              
     47 
    4848      # If this controller was instantiated to process a component request, 
    4949      # +parent_controller+ points to the instantiator of this controller. 
    5050      base.send :attr_accessor, :parent_controller 
    51        
     51 
    5252      base.class_eval do 
    5353        alias_method_chain :process_cleanup, :components 
     
    5555        alias_method_chain :flash, :components 
    5656 
    57         alias_method :component_request?, :parent_controller        
     57        alias_method :component_request?, :parent_controller 
    5858      end 
    5959    end 
     
    6666        controller.process(request, response) 
    6767      end 
    68  
    69       # Set the template root to be one directory behind the root dir of the controller. Examples: 
    70       #   /code/weblog/components/admin/users_controller.rb with Admin::UsersController  
    71       #     will use /code/weblog/components as template root  
    72       #     and find templates in /code/weblog/components/admin/users/ 
    73       # 
    74       #   /code/weblog/components/admin/parties/users_controller.rb with Admin::Parties::UsersController  
    75       #     will also use /code/weblog/components as template root  
    76       #     and find templates in /code/weblog/components/admin/parties/users/ 
    77       def uses_component_template_root 
    78         path_of_calling_controller = File.dirname(caller[1].split(/:\d+:/, 2).first) 
    79         path_of_controller_root    = path_of_calling_controller.sub(/#{Regexp.escape(File.dirname(controller_path))}$/, "") 
    80         prepend_view_path path_of_controller_root 
    81         view_paths.first 
    82       end 
    83  
    84       deprecate :uses_component_template_root => 'Components are deprecated and will be removed in Rails 2.0.' 
    8568    end 
    8669 
     
    9174        process_without_components(request, response, method, *arguments) 
    9275      end 
    93        
     76 
    9477      protected 
    9578        # Renders the component specified as the response for the current method 
  • trunk/actionpack/test/controller/components_test.rb

    r5631 r6403  
    2121    render_template "Are you there? <%= render_component(:action => 'internal_callee') %>" 
    2222  end 
    23    
     23 
    2424  def internal_callee 
    2525    render_text "Yes, ma'am" 
     
    3333    render_component(:controller => "callee", :action => "use_flash") 
    3434  end 
    35    
     35 
    3636  def calling_redirected 
    3737    render_component(:controller => "callee", :action => "redirected") 
    3838  end 
    39    
     39 
    4040  def calling_redirected_as_string 
    4141    render_template "<%= render_component(:controller => 'callee', :action => 'redirected') %>" 
     
    4949    render_text "#{params[:name] || "Lady"} of the House, speaking" 
    5050  end 
    51    
     51 
    5252  def blowing_up 
    5353    render_text "It's game over, man, just game over, man!", "500 Internal Server Error" 
    5454  end 
    55    
     55 
    5656  def set_flash 
    5757    flash[:notice] = 'My stoney baby' 
    5858    render :text => 'flash is set' 
    5959  end 
    60    
     60 
    6161  def use_flash 
    6262    render :text => flash[:notice] || 'no flash' 
    6363  end 
    64    
     64 
    6565  def redirected 
    6666    redirect_to :controller => "callee", :action => "being_called" 
     
    8686    assert_equal "David of the House, speaking", @response.body 
    8787  end 
    88    
     88 
    8989  def test_calling_from_controller_with_different_status_code 
    9090    get :calling_from_controller_with_different_status_code 
     
    9696    assert_equal "Ring, ring: Lady of the House, speaking", @response.body 
    9797  end 
    98    
     98 
    9999  def test_internal_calling 
    100100    get :internal_caller 
    101101    assert_equal "Are you there? Yes, ma'am", @response.body 
    102102  end 
    103    
     103 
    104104  def test_flash 
    105105    get :set_flash 
     
    110110    assert_equal 'no flash', @response.body 
    111111  end 
    112    
     112 
    113113  def test_component_redirect_redirects 
    114114    get :calling_redirected 
    115      
     115 
    116116    assert_redirected_to :action => "being_called" 
    117117  end 
    118    
     118 
    119119  def test_component_multiple_redirect_redirects 
    120120    test_component_redirect_redirects 
    121121    test_internal_calling 
    122122  end 
    123    
     123 
    124124  def test_component_as_string_redirect_renders_redirecte_action 
    125125    get :calling_redirected_as_string 
    126      
     126 
    127127    assert_equal "Lady of the House, speaking", @response.body 
    128128  end 
    129129end 
    130  
    131 module A 
    132   module B 
    133     module C 
    134       class NestedController < ActionController::Base 
    135         # Stub for uses_component_template_root 
    136         def self.caller 
    137           [ '/path/to/active_support/deprecation.rb:93:in `uses_component_template_root', 
    138             './test/fixtures/a/b/c/nested_controller.rb' ] 
    139         end 
    140       end 
    141     end 
    142   end 
    143 end 
    144  
    145 class UsesComponentTemplateRootTest < Test::Unit::TestCase 
    146   def test_uses_component_template_root 
    147     assert_deprecated 'uses_component_template_root' do 
    148       assert_equal './test/fixtures/', A::B::C::NestedController.uses_component_template_root 
    149     end 
    150   end 
    151 end