From 12a75736303d67f17e29f25aa635d521a56d0de2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Feb 2005 13:50:13 +0000 Subject: Added new keyword to specify load paths as being component based. Added better logging for component calls git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@713 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/base.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/base.rb') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 421438414d..d68faaf2f2 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -224,7 +224,7 @@ module ActionController #:nodoc: # Template root determines the base from which template references will be made. So a call to render("test/template") # will be converted to "#{template_root}/test/template.rhtml". - cattr_accessor :template_root + class_inheritable_accessor :template_root # The logger is used for generating information on the action run-time (including benchmarking) if available. # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers. @@ -298,6 +298,20 @@ module ActionController #:nodoc: def hide_actions(*names) write_inheritable_attribute(:hidden_actions, hidden_actions | names.collect {|n| n.to_s}) 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[0].split(/:\d+:/).first) + path_of_controller_root = path_of_calling_controller.sub(/#{controller_path.split("/")[0..-2]}$/, "") + self.template_root = path_of_controller_root + end end public -- cgit v1.2.3