Pass formats to lookup_context

Before we were changing the state of the lookup_context for the duration
of the with_layout_format block, but since we already know the formats
we can just pass it explicitly.

Related with 8d7ce0f22a
This commit is contained in:
Rafael Mendonça França 2015-08-24 15:16:59 -03:00
parent b58808ed6a
commit face604266
2 changed files with 9 additions and 8 deletions

View File

@ -277,7 +277,7 @@ module ActionView
remove_possible_method(:_layout)
prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"]
default_behavior = "lookup_context.find_all('#{_implied_layout_name}', #{prefixes.inspect}).first || super"
default_behavior = "lookup_context.find_all('#{_implied_layout_name}', #{prefixes.inspect}, false, [], { formats: formats }).first || super"
name_clause = if name
default_behavior
else
@ -316,7 +316,7 @@ module ActionView
end
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _layout
def _layout(formats)
if _conditional_layout?
#{layout_definition}
else
@ -372,7 +372,7 @@ module ActionView
end
# This will be overwritten by _write_layout_method
def _layout; end
def _layout(*); end
# Determine the layout for a given name, taking into account the name type.
#
@ -382,8 +382,8 @@ module ActionView
case name
when String then _normalize_layout(name)
when Proc then name
when true then Proc.new { _default_layout(true) }
when :default then Proc.new { _default_layout(false) }
when true then Proc.new { _default_layout(formats, true) }
when :default then Proc.new { _default_layout(formats, false) }
when false, nil then nil
else
raise ArgumentError,
@ -399,14 +399,15 @@ module ActionView
# Optionally raises an exception if the layout could not be found.
#
# ==== Parameters
# * <tt>formats</tt> - The formats accepted to this layout
# * <tt>require_layout</tt> - If set to true and layout is not found,
# an ArgumentError exception is raised (defaults to false)
#
# ==== Returns
# * <tt>template</tt> - The template object for the default layout (or nil)
def _default_layout(require_layout = false)
def _default_layout(formats, require_layout = false)
begin
value = _layout if action_has_layout?
value = _layout(formats) if action_has_layout?
rescue NameError => e
raise e, "Could not render layout: #{e.message}"
end

View File

@ -93,7 +93,7 @@ module ActionView
raise unless template_exists?(layout, nil, false, keys, all_details)
end
when Proc
resolve_layout(layout.call, keys, formats)
resolve_layout(layout.call(formats), keys, formats)
else
layout
end