Deprecation: remove toplevel components directory and uses_component_template_root.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6403 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-03-13 04:46:12 +00:00
parent ee71950f60
commit da87839c89
3 changed files with 25 additions and 64 deletions

@ -1,6 +1,6 @@
*SVN*
* Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. [Jeremy Kemper]
* Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. Remove uses_component_template_root for toplevel components directory. [Jeremy Kemper]
* Consistent public/protected/private visibility for chained methods. #7813 [Dan Manges]

@ -17,20 +17,20 @@ module ActionController #:nodoc:
# end
#
# The same can be done in a view to do a partial rendering:
#
# Let's see a greeting:
#
# Let's see a greeting:
# <%= render_component :controller => "greeter", :action => "hello_world" %>
#
# It is also possible to specify the controller as a class constant, bypassing the inflector
# code to compute the controller class at runtime:
#
#
# <%= render_component :controller => GreeterController, :action => "hello_world" %>
#
# == When to use components
#
# Components should be used with care. They're significantly slower than simply splitting reusable parts into partials and
# conceptually more complicated. Don't use components as a way of separating concerns inside a single application. Instead,
# reserve components to those rare cases where you truly have reusable view and controller elements that can be employed
# reserve components to those rare cases where you truly have reusable view and controller elements that can be employed
# across many applications at once.
#
# So to repeat: Components are a special-purpose approach that can often be replaced with better use of partials and filters.
@ -40,21 +40,21 @@ def self.included(base) #:nodoc:
base.extend(ClassMethods)
base.helper do
def render_component(options)
def render_component(options)
@controller.send(:render_component_as_string, options)
end
end
# If this controller was instantiated to process a component request,
# +parent_controller+ points to the instantiator of this controller.
base.send :attr_accessor, :parent_controller
base.class_eval do
alias_method_chain :process_cleanup, :components
alias_method_chain :set_session_options, :components
alias_method_chain :flash, :components
alias_method :component_request?, :parent_controller
alias_method :component_request?, :parent_controller
end
end
@ -65,23 +65,6 @@ def process_with_components(request, response, parent_controller = nil) #:nodoc:
controller.parent_controller = parent_controller
controller.process(request, response)
end
# Set the template root to be one directory behind the root dir of the controller. Examples:
# /code/weblog/components/admin/users_controller.rb with Admin::UsersController
# will use /code/weblog/components as template root
# and find templates in /code/weblog/components/admin/users/
#
# /code/weblog/components/admin/parties/users_controller.rb with Admin::Parties::UsersController
# will also use /code/weblog/components as template root
# and find templates in /code/weblog/components/admin/parties/users/
def uses_component_template_root
path_of_calling_controller = File.dirname(caller[1].split(/:\d+:/, 2).first)
path_of_controller_root = path_of_calling_controller.sub(/#{Regexp.escape(File.dirname(controller_path))}$/, "")
prepend_view_path path_of_controller_root
view_paths.first
end
deprecate :uses_component_template_root => 'Components are deprecated and will be removed in Rails 2.0.'
end
module InstanceMethods
@ -90,7 +73,7 @@ def process_with_components(request, response, method = :perform_action, *argume
flash.discard if component_request?
process_without_components(request, response, method, *arguments)
end
protected
# Renders the component specified as the response for the current method
def render_component(options) #:doc:

@ -20,7 +20,7 @@ def calling_from_template
def internal_caller
render_template "Are you there? <%= render_component(:action => 'internal_callee') %>"
end
def internal_callee
render_text "Yes, ma'am"
end
@ -32,11 +32,11 @@ def set_flash
def use_flash
render_component(:controller => "callee", :action => "use_flash")
end
def calling_redirected
render_component(:controller => "callee", :action => "redirected")
end
def calling_redirected_as_string
render_template "<%= render_component(:controller => 'callee', :action => 'redirected') %>"
end
@ -48,20 +48,20 @@ class CalleeController < ActionController::Base
def being_called
render_text "#{params[:name] || "Lady"} of the House, speaking"
end
def blowing_up
render_text "It's game over, man, just game over, man!", "500 Internal Server Error"
end
def set_flash
flash[:notice] = 'My stoney baby'
render :text => 'flash is set'
end
def use_flash
render :text => flash[:notice] || 'no flash'
end
def redirected
redirect_to :controller => "callee", :action => "being_called"
end
@ -85,7 +85,7 @@ def test_calling_from_controller_with_params
get :calling_from_controller_with_params
assert_equal "David of the House, speaking", @response.body
end
def test_calling_from_controller_with_different_status_code
get :calling_from_controller_with_different_status_code
assert_equal 500, @response.response_code
@ -95,12 +95,12 @@ def test_calling_from_template
get :calling_from_template
assert_equal "Ring, ring: Lady of the House, speaking", @response.body
end
def test_internal_calling
get :internal_caller
assert_equal "Are you there? Yes, ma'am", @response.body
end
def test_flash
get :set_flash
assert_equal 'My stoney baby', flash[:notice]
@ -109,43 +109,21 @@ def test_flash
get :use_flash
assert_equal 'no flash', @response.body
end
def test_component_redirect_redirects
get :calling_redirected
assert_redirected_to :action => "being_called"
end
def test_component_multiple_redirect_redirects
test_component_redirect_redirects
test_internal_calling
end
def test_component_as_string_redirect_renders_redirecte_action
get :calling_redirected_as_string
assert_equal "Lady of the House, speaking", @response.body
end
end
module A
module B
module C
class NestedController < ActionController::Base
# Stub for uses_component_template_root
def self.caller
[ '/path/to/active_support/deprecation.rb:93:in `uses_component_template_root',
'./test/fixtures/a/b/c/nested_controller.rb' ]
end
end
end
end
end
class UsesComponentTemplateRootTest < Test::Unit::TestCase
def test_uses_component_template_root
assert_deprecated 'uses_component_template_root' do
assert_equal './test/fixtures/', A::B::C::NestedController.uses_component_template_root
end
end
end