1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Drive the final stake through @content_for_*'s heart!

This commit is contained in:
Yehuda Katz + Carl Lerche 2009-06-17 18:08:45 -07:00
parent 65102c8f1a
commit a9ad763c86
8 changed files with 23 additions and 36 deletions

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -1,3 +1,3 @@
xml.wrapper do
xml << @content_for_layout
xml << yield
end

View file

@ -1 +1 @@
<html><%= @content_for_layout %><%= @variable_for_layout %></html>
<html><%= yield %><%= @variable_for_layout %></html>

View file

@ -1,2 +1,2 @@
<title><%= @title || @content_for_title %></title>
<%= @content_for_layout -%>
<title><%= @title || yield(:title) %></title>
<%= yield -%>