未验证 提交 5e29ea0f 编写于 作者: A Aaron Patterson 提交者: GitHub

Merge pull request #35369 from rails/fewer-lookup-context-calls

Pass lookup context to the layout handlers
...@@ -322,7 +322,7 @@ def _write_layout_method # :nodoc: ...@@ -322,7 +322,7 @@ def _write_layout_method # :nodoc:
end end
class_eval <<-RUBY, __FILE__, __LINE__ + 1 class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _layout(formats) def _layout(lookup_context, formats)
if _conditional_layout? if _conditional_layout?
#{layout_definition} #{layout_definition}
else else
...@@ -388,8 +388,8 @@ def _layout_for_option(name) ...@@ -388,8 +388,8 @@ def _layout_for_option(name)
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 { |formats| _default_layout(formats, true) } when true then Proc.new { |lookup_context, formats| _default_layout(lookup_context, formats, true) }
when :default then Proc.new { |formats| _default_layout(formats, false) } when :default then Proc.new { |lookup_context, formats| _default_layout(lookup_context, formats, false) }
when false, nil then nil when false, nil then nil
else else
raise ArgumentError, raise ArgumentError,
...@@ -411,9 +411,9 @@ def _normalize_layout(value) ...@@ -411,9 +411,9 @@ def _normalize_layout(value)
# #
# ==== 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(formats, require_layout = false) def _default_layout(lookup_context, formats, require_layout = false)
begin begin
value = _layout(formats) if action_has_layout? value = _layout(lookup_context, 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
......
...@@ -88,7 +88,7 @@ def resolve_layout(layout, keys, formats) ...@@ -88,7 +88,7 @@ def resolve_layout(layout, keys, formats)
raise unless template_exists?(layout, nil, false, [], all_details) raise unless template_exists?(layout, nil, false, [], all_details)
end end
when Proc when Proc
resolve_layout(layout.call(formats), keys, formats) resolve_layout(layout.call(@lookup_context, formats), keys, formats)
else else
layout layout
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册