aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-20 13:50:13 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-20 13:50:13 +0000
commit12a75736303d67f17e29f25aa635d521a56d0de2 (patch)
treee31f5c9a520036016ab9ae642bc70d320f899205 /actionpack
parentbeb2875094d8038b1d5d8fc1a5943884cf96ccf4 (diff)
downloadrails-12a75736303d67f17e29f25aa635d521a56d0de2.tar.gz
rails-12a75736303d67f17e29f25aa635d521a56d0de2.tar.bz2
rails-12a75736303d67f17e29f25aa635d521a56d0de2.zip
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
Diffstat (limited to 'actionpack')
-rwxr-xr-xactionpack/lib/action_controller/base.rb16
-rw-r--r--actionpack/lib/action_controller/components.rb17
-rw-r--r--actionpack/lib/action_controller/dependencies.rb4
-rw-r--r--actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml2
4 files changed, 31 insertions, 8 deletions
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
diff --git a/actionpack/lib/action_controller/components.rb b/actionpack/lib/action_controller/components.rb
index 148f7b9119..877d8888bd 100644
--- a/actionpack/lib/action_controller/components.rb
+++ b/actionpack/lib/action_controller/components.rb
@@ -2,13 +2,21 @@ module ActionController #:nodoc:
module Components #:nodoc:
def self.append_features(base)
super
- base.helper { def render_component(options) @controller.send(:component_response, options).body end }
+ base.helper do
+ def render_component(options)
+ @controller.logger.info("Start rendering component (#{options.inspect}): ")
+ @controller.send(:component_response, options).body
+ @controller.logger.info("\n\nEnd of component rendering")
+ end
+ end
end
protected
def render_component(options = {}) #:doc:
response = component_response(options)
+ logger.info "Rendering component (#{options.inspect}): "
render_text(response.body, response.headers["Status"])
+ logger.info("\n\nEnd of component rendering")
end
private
@@ -22,8 +30,11 @@ module ActionController #:nodoc:
def component_request(options)
component_request = @request.dup
- component_request.send(:instance_variable_set, :@parameters, (options[:params] || {}).merge({ "controller" => options[:controller], "action" => options[:action] }))
- component_request
+ component_request.send(
+ :instance_variable_set, :@parameters,
+ (options[:params] || {}).merge({ "controller" => options[:controller], "action" => options[:action] })
+ )
+ return component_request
end
end
end
diff --git a/actionpack/lib/action_controller/dependencies.rb b/actionpack/lib/action_controller/dependencies.rb
index be32417894..1f8ae7c22d 100644
--- a/actionpack/lib/action_controller/dependencies.rb
+++ b/actionpack/lib/action_controller/dependencies.rb
@@ -88,6 +88,4 @@ module ActionController #:nodoc:
end
end
end
-end
-
-Controllers = Dependencies::LoadingModule.new(File.expand_path(File.join(RAILS_ROOT, 'app', 'controllers'))) if defined?(RAILS_ROOT) \ No newline at end of file
+end \ No newline at end of file
diff --git a/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml b/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml
index d807c4fb79..30a1a05d1f 100644
--- a/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml
+++ b/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml
@@ -1,4 +1,4 @@
-<% unless @exception.blamed_files.empty? %>
+<% if @exception.blamed_files && !@exception.blamed_files.empty? %>
<a href="#" onclick="document.getElementById('blame_trace').style.display='block'; return false;">Show blamed files</a>
<pre id="blame_trace" style="display:none"><code><%=h @exception.describe_blame %></code></pre>
<% end %>