Skip to content

Instantly share code, notes, and snippets.

@fbrubacher
Created May 14, 2010 18:44
Show Gist options
  • Save fbrubacher/401480 to your computer and use it in GitHub Desktop.
Save fbrubacher/401480 to your computer and use it in GitHub Desktop.
# Returns the default layout for this controller and a given set of details.
# Optionally raises an exception if the layout could not be found.
#
# ==== Parameters
# details<Hash>:: A list of details to restrict the search by. This
# might include details like the format or locale of the template.
# require_layout<Boolean>:: If this is true, raise an ArgumentError
# with details about the fact that the exception could not be
# found (defaults to false)
#
# ==== Returns
# Template:: The template object for the default layout (or nil)
def _default_layout(require_layout = false)
begin
if action_has_layout?
layout_name = _layout
else
layout = self.class.instance_variable_get(:@_parent_layout)
layout_name = layout.is_a?(Proc) layout.call(self) : layout
end
rescue NameError => e
raise NoMethodError,
"You specified #{@_layout.inspect} as the layout, but no such method was found"
end
if require_layout && action_has_layout? && !layout_name
raise ArgumentError,
"There was no default layout for #{self.class} in #{view_paths.inspect}"
end
layout_name
end
def _include_layout?(options)
(options.keys & [:text, :inline, :partial]).empty? || options.key?(:layout)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment