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

Eliminate internal render stack since we only need its head and tail

This commit is contained in:
Jeremy Kemper 2009-03-12 12:22:52 -07:00
parent 9230678104
commit c8c2b3820e
2 changed files with 26 additions and 16 deletions

View file

@ -221,10 +221,12 @@ module ActionView #:nodoc:
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc: def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
@assigns = assigns_for_first_render @assigns = assigns_for_first_render
@assigns_added = nil @assigns_added = nil
@_render_stack = []
@controller = controller @controller = controller
@helpers = ProxyModule.new(self) @helpers = ProxyModule.new(self)
self.view_paths = view_paths self.view_paths = view_paths
@_first_template = nil
@_current_template = nil
end end
attr_reader :view_paths attr_reader :view_paths
@ -286,7 +288,19 @@ module ActionView #:nodoc:
# Access the current template being rendered. # Access the current template being rendered.
# Returns a ActionView::Template object. # Returns a ActionView::Template object.
def template def template
@_render_stack.last @_current_template
end
def template=(template) #:nodoc:
@_first_template ||= template
@_current_template = template
end
def with_template(current_template)
last_template, self.template = template, current_template
yield
ensure
self.template = last_template
end end
private private

View file

@ -27,13 +27,11 @@ module ActionView
def render(view, local_assigns = {}) def render(view, local_assigns = {})
compile(local_assigns) compile(local_assigns)
stack = view.instance_variable_get(:@_render_stack) view.with_template self do
stack.push(self)
view.send(:_evaluate_assigns_and_ivars) view.send(:_evaluate_assigns_and_ivars)
view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type) view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type)
result = view.send(method_name(local_assigns), local_assigns) do |*names| view.send(method_name(local_assigns), local_assigns) do |*names|
ivar = :@_proc_for_layout ivar = :@_proc_for_layout
if !view.instance_variable_defined?(:"@content_for_#{names.first}") && view.instance_variable_defined?(ivar) && (proc = view.instance_variable_get(ivar)) if !view.instance_variable_defined?(:"@content_for_#{names.first}") && view.instance_variable_defined?(ivar) && (proc = view.instance_variable_get(ivar))
view.capture(*names, &proc) view.capture(*names, &proc)
@ -41,9 +39,7 @@ module ActionView
view.instance_variable_get(ivar) view.instance_variable_get(ivar)
end end
end end
end
stack.pop
result
end end
def method_name(local_assigns) def method_name(local_assigns)