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

View File

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