1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make conditional_layout? private and update documentation

The conditional_layout? method is not for public use and doesn't
actually do what the documentation suggested it does. It's actually
used to determine whether or not to use the explicit layout definition
defined in a controller or use the implicit layout definition.

Also documentation was added for the action_has_layout? method which
acts as a master switch for disabling the layout for the current
action. This method was added so that action caching didn't depend
on accessing layout internals but is also used by third-parties,
most notably the [Hobo][1] application.

[1]: https://github.com/hobo/hobo
This commit is contained in:
Andrew White 2012-12-17 16:12:07 +00:00
parent d551701b11
commit dcb318ee43

View file

@ -212,21 +212,23 @@ module AbstractController
delegate :_layout_conditions, :to => "self.class" delegate :_layout_conditions, :to => "self.class"
module ClassMethods module ClassMethods
def inherited(klass) def inherited(klass) # :nodoc:
super super
klass._write_layout_method klass._write_layout_method
end end
# This module is mixed in if layout conditions are provided. This means # This module is mixed in if layout conditions are provided. This means
# that if no layout conditions are used, this method is not used # that if no layout conditions are used, this method is not used
module LayoutConditions module LayoutConditions # :nodoc:
# Determines whether the current action has a layout by checking the private
# action name against the :only and :except conditions set on the
# layout. # Determines whether the current action has a layout definition by
# checking the action name against the :only and :except conditions
# set by the <tt>layout</tt> method.
# #
# ==== Returns # ==== Returns
# * <tt> Boolean</tt> - True if the action has a layout, false otherwise. # * <tt> Boolean</tt> - True if the action has a layout definition, false otherwise.
def conditional_layout? def _conditional_layout?
return unless super return unless super
conditions = _layout_conditions conditions = _layout_conditions
@ -271,7 +273,7 @@ module AbstractController
# #
# ==== Returns # ==== Returns
# * <tt>String</tt> - A template name # * <tt>String</tt> - A template name
def _implied_layout_name def _implied_layout_name # :nodoc:
controller_path controller_path
end end
@ -279,7 +281,7 @@ module AbstractController
# #
# If a layout is not explicitly mentioned then look for a layout with the controller's name. # If a layout is not explicitly mentioned then look for a layout with the controller's name.
# if nothing is found then try same procedure to find super class's layout. # if nothing is found then try same procedure to find super class's layout.
def _write_layout_method def _write_layout_method # :nodoc:
remove_possible_method(:_layout) remove_possible_method(:_layout)
prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"] prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"]
@ -318,7 +320,7 @@ module AbstractController
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _layout def _layout
if conditional_layout? if _conditional_layout?
#{layout_definition} #{layout_definition}
else else
#{name_clause} #{name_clause}
@ -329,7 +331,7 @@ module AbstractController
end end
end end
def _normalize_options(options) def _normalize_options(options) # :nodoc:
super super
if _include_layout?(options) if _include_layout?(options)
@ -340,21 +342,27 @@ module AbstractController
attr_internal_writer :action_has_layout attr_internal_writer :action_has_layout
def initialize(*) def initialize(*) # :nodoc:
@_action_has_layout = true @_action_has_layout = true
super super
end end
# Controls whether an action should be rendered using a layout.
# If you want to disable any <tt>layout</tt> settings for the
# current action so that it is rendered without a layout then
# either override this method in your controller to return false
# for that action or set the <tt>action_has_layout</tt> attribute
# to false before rendering.
def action_has_layout? def action_has_layout?
@_action_has_layout @_action_has_layout
end end
def conditional_layout? private
def _conditional_layout?
true true
end end
private
# This will be overwritten by _write_layout_method # This will be overwritten by _write_layout_method
def _layout; end def _layout; end