From 0367317dd62ecd177d57d469a4d57974b75e425b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 22 May 2005 07:43:05 +0000 Subject: Deprecated redirect_to_path and redirect_to_url in favor of letting redirect_to do the right thing when passed either a path or url. Introduced r as a unified method for render (still under construction) git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1349 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/layout.rb | 34 +++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index aca3dbd797..37dba36186 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -5,6 +5,10 @@ module ActionController #:nodoc: base.class_eval do alias_method :render_without_layout, :render alias_method :render, :render_with_layout + + alias_method :r_without_layout, :r + alias_method :r, :r_with_layout + class << self alias_method :inherited_without_layout, :inherited end @@ -212,8 +216,33 @@ module ActionController #:nodoc: end end + def r_with_layout(options = {}) + if (layout = active_layout_for_r(options)) && options[:text] + add_variables_to_assigns + logger.info("Rendering #{template_name} within #{layout}") unless logger.nil? + + @content_for_layout = r_without_layout(options) + add_variables_to_assigns + + erase_render_results + r_without_layout(options.merge({ :text => @template.render_file(layout, true)})) + else + r_without_layout(options) + end + end + private - + def active_layout_for_r(options = {}) + case options[:layout] + when FalseClass + nil + when NilClass + active_layout if action_has_layout? + else + active_layout(options[:layout]) + end + end + def action_has_layout? conditions = self.class.layout_conditions case @@ -225,6 +254,5 @@ module ActionController #:nodoc: true end end - end -end +end \ No newline at end of file -- cgit v1.2.3