aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-17 18:08:45 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-17 18:08:45 -0700
commita9ad763c86e110c280be0b7a763496f9e1204de0 (patch)
treef3f6fe2d86a4536cae6f1a9a7ddf73d67c59f2e0 /actionpack
parent65102c8f1a55c8d73e44b62eed5e689017ace7cd (diff)
downloadrails-a9ad763c86e110c280be0b7a763496f9e1204de0.tar.gz
rails-a9ad763c86e110c280be0b7a763496f9e1204de0.tar.bz2
rails-a9ad763c86e110c280be0b7a763496f9e1204de0.zip
Drive the final stake through @content_for_*'s heart!
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/legacy/layout.rb3
-rw-r--r--actionpack/lib/action_view/base.rb4
-rw-r--r--actionpack/lib/action_view/helpers/capture_helper.rb5
-rw-r--r--actionpack/lib/action_view/render/partials.rb7
-rw-r--r--actionpack/lib/action_view/render/rendering.rb32
-rw-r--r--actionpack/test/fixtures/layouts/builder.builder2
-rw-r--r--actionpack/test/fixtures/layouts/standard.html.erb2
-rw-r--r--actionpack/test/fixtures/layouts/talk_from_action.erb4
8 files changed, 23 insertions, 36 deletions
diff --git a/actionpack/lib/action_controller/legacy/layout.rb b/actionpack/lib/action_controller/legacy/layout.rb
index 3046e082d9..3f3d20b95f 100644
--- a/actionpack/lib/action_controller/legacy/layout.rb
+++ b/actionpack/lib/action_controller/legacy/layout.rb
@@ -44,9 +44,6 @@ module ActionController #:nodoc:
# hello world
# // The footer part of this layout
#
- # NOTE: The old notation for rendering the view from a layout was to expose the magic <tt>@content_for_layout</tt> instance
- # variable. The preferred notation now is to use <tt>yield</tt>, as documented above.
- #
# == Accessing shared variables
#
# Layouts have access to variables specified in the content pages and vice versa. This allows you to have layouts with
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 1ca6f839a8..b994c7b141 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -170,12 +170,13 @@ module ActionView #:nodoc:
attr_accessor :base_path, :assigns, :template_extension, :formats
attr_accessor :controller
+ attr_internal :captures
attr_accessor :output_buffer
class << self
delegate :erb_trim_mode=, :to => 'ActionView::TemplateHandlers::ERB'
- delegate :logger, :to => 'ActionController::Base'
+ delegate :logger, :to => 'ActionController::Base', :allow_nil => true
end
@@debug_rjs = false
@@ -232,6 +233,7 @@ module ActionView #:nodoc:
@assigns = assigns_for_first_render
@controller = controller
@helpers = ProxyModule.new(self)
+ @_content_for = Hash.new {|h,k| h[k] = "" }
self.view_paths = view_paths
end
diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb
index b4197479a0..1c29eb3b81 100644
--- a/actionpack/lib/action_view/helpers/capture_helper.rb
+++ b/actionpack/lib/action_view/helpers/capture_helper.rb
@@ -116,10 +116,9 @@ module ActionView
# named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now
# <tt><%= yield :footer %></tt>.
def content_for(name, content = nil, &block)
- ivar = "@content_for_#{name}"
content = capture(&block) if block_given?
- instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{content}")
- nil
+ return @_content_for[name] << content if content
+ @_content_for[name]
end
# Use an alternate output buffer for the duration of the block.
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index eacf117bea..87314fff67 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -245,13 +245,6 @@ module ActionView
end
end
- def _render_partial_with_block(layout, block, options)
- @_proc_for_layout = block
- concat(_render_partial(options.merge(:partial => layout)))
- ensure
- @_proc_for_layout = nil
- end
-
def _render_partial_with_layout(layout, options)
if layout
prefix = controller && !layout.include?("/") ? controller.controller_path : nil
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index d120631e5d..a720012d1c 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -51,13 +51,12 @@ module ActionView
end
begin
- original_content_for_layout = @content_for_layout if defined?(@content_for_layout)
- @content_for_layout = content
+ old_content, @_content_for[:layout] = @_content_for[:layout], content
- @cached_content_for_layout = @content_for_layout
+ @cached_content_for_layout = @_content_for[:layout]
_render_template(layout, locals)
ensure
- @content_for_layout = original_content_for_layout
+ @_content_for[:layout] = old_content
end
end
@@ -66,12 +65,11 @@ module ActionView
_evaluate_assigns_and_ivars
template.render(self, local_assigns) do |*names|
- if !instance_variable_defined?(:"@content_for_#{names.first}") &&
- instance_variable_defined?(:@_proc_for_layout) && (proc = @_proc_for_layout)
- capture(*names, &proc)
- elsif instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}")
- instance_variable_get(ivar)
- end
+ if !@_content_for.key?(names.first) && @_proc_for_layout
+ capture(*names, &@_proc_for_layout)
+ elsif content = @_content_for[names.first || :layout]
+ content
+ end
end
end
rescue Exception => e
@@ -100,20 +98,18 @@ module ActionView
end
def _render_template_with_layout(template, layout = nil, options = {}, partial = false)
- if controller && logger
- logger.info("Rendering #{template.identifier}" +
- (options[:status] ? " (#{options[:status]})" : ''))
- end
-
+ logger && logger.info("Rendering #{template.identifier}#{' (#{options[:status]})' if options[:status]}")
+
+ locals = options[:locals] || {}
+
content = if partial
object = partial unless partial == true
_render_partial_object(template, options, object)
else
- _render_template(template, options[:locals] || {})
+ _render_template(template, locals)
end
- return content unless layout
- _render_content_with_layout(content, layout, options[:locals] || {})
+ layout ? _render_content_with_layout(content, layout, locals) : content
end
end
end \ No newline at end of file
diff --git a/actionpack/test/fixtures/layouts/builder.builder b/actionpack/test/fixtures/layouts/builder.builder
index 729af4b8bc..7c7d4b2dd1 100644
--- a/actionpack/test/fixtures/layouts/builder.builder
+++ b/actionpack/test/fixtures/layouts/builder.builder
@@ -1,3 +1,3 @@
xml.wrapper do
- xml << @content_for_layout
+ xml << yield
end \ No newline at end of file
diff --git a/actionpack/test/fixtures/layouts/standard.html.erb b/actionpack/test/fixtures/layouts/standard.html.erb
index 368764e6f4..5e6c24fe39 100644
--- a/actionpack/test/fixtures/layouts/standard.html.erb
+++ b/actionpack/test/fixtures/layouts/standard.html.erb
@@ -1 +1 @@
-<html><%= @content_for_layout %><%= @variable_for_layout %></html> \ No newline at end of file
+<html><%= yield %><%= @variable_for_layout %></html> \ No newline at end of file
diff --git a/actionpack/test/fixtures/layouts/talk_from_action.erb b/actionpack/test/fixtures/layouts/talk_from_action.erb
index 187aab07a2..bf53fdb785 100644
--- a/actionpack/test/fixtures/layouts/talk_from_action.erb
+++ b/actionpack/test/fixtures/layouts/talk_from_action.erb
@@ -1,2 +1,2 @@
-<title><%= @title || @content_for_title %></title>
-<%= @content_for_layout -%> \ No newline at end of file
+<title><%= @title || yield(:title) %></title>
+<%= yield -%> \ No newline at end of file