def _write_layout_method
remove_possible_method(:_layout)
prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"]
name_clause = if name
"lookup_context.find_all(\"\#{_implied_layout_name}\", \#{prefixes.inspect}).first || super\n"
end
if defined?(@_layout)
layout_definition = case @_layout
when String
@_layout.inspect
when Symbol
"\#{@_layout}.tap do |layout|\nunless layout.is_a?(String) || !layout\nraise ArgumentError, \"Your layout method :\#{@_layout} returned \\\#{layout}. It \" \\\n\"should have returned a String, false, or nil\"\nend\nend\n"
when Proc
define_method :_layout_from_proc, &@_layout
"_layout_from_proc(self)"
when false
nil
when true
raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil"
when nil
name_clause
end
else
parent = self.superclass.instance_variable_get(:@_layout)
@_layout = nil
inspect = parent.is_a?(Proc) ? parent.inspect : parent
layout_definition = if parent.nil?
name_clause
elsif name
"if template = lookup_context.find_all(\"\#{_implied_layout_name}\", \#{prefixes.inspect}).first\nActiveSupport::Deprecation.warn 'Layout found at \"\#{_implied_layout_name}\" for \#{name} but parent controller ' \\\n'set layout to \#{inspect.inspect}. Please explicitly set your layout to \"\#{_implied_layout_name}\" ' \\\n'or set it to nil to force a dynamic lookup.'\ntemplate\nelse\nsuper\nend\n"
end
end
self.class_eval "def _layout\nif conditional_layout?\n\#{layout_definition}\nelse\n\#{name_clause}\nend\nend\nprivate :_layout\n", __FILE__, __LINE__ + 1
end