From d42d97d2e3f0bdef2163cc14daa181903e0b198d Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Thu, 6 Oct 2011 10:39:37 +0400 Subject: Fix comment in AbstractController callbacks --- actionpack/lib/abstract_controller/callbacks.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index 14c984e41f..7004e607a1 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -177,7 +177,7 @@ module AbstractController def prepend_#{filter}_filter(*names, &blk) # def prepend_before_filter(*names, &blk) _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options| options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} # options[:if] = (Array.wrap(options[:if]) << "!halted") if false - set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) # set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) + set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) # set_callback(:process_action, :before, name, options.merge(:prepend => true)) end # end end # end @@ -185,7 +185,7 @@ module AbstractController # for details on the allowed parameters. def skip_#{filter}_filter(*names, &blk) # def skip_before_filter(*names, &blk) _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options| - skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :#{filter}, name, options) + skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :before, name, options) end # end end # end -- cgit v1.2.3 From 759906d51272534941843fc80ae9f579b28c336c Mon Sep 17 00:00:00 2001 From: Dalibor Nasevic Date: Sun, 6 Nov 2011 14:43:11 +0100 Subject: Fixed stale doc in AbstractController::Layouts --- actionpack/lib/abstract_controller/layouts.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 10aa34c76b..bbf5efe565 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -213,7 +213,7 @@ module AbstractController # true:: raise an ArgumentError # # ==== Parameters - # * String, Symbol, false - The layout to use. + # * layout - The layout to use. # # ==== Options (conditions) # * :only - A list of actions to apply this layout to. @@ -310,14 +310,10 @@ module AbstractController # This will be overwritten by _write_layout_method def _layout; end - # Determine the layout for a given name and details, taking into account - # the name type. + # Determine the layout for a given name, taking into account the name type. # # ==== Parameters # * name - The name of the template - # * details - A list of details to restrict - # the lookup to. By default, layout lookup is limited to the - # formats specified for the current request. def _layout_for_option(name) case name when String then name @@ -330,15 +326,12 @@ module AbstractController end end - # Returns the default layout for this controller and a given set of details. + # Returns the default layout for this controller. # Optionally raises an exception if the layout could not be found. # # ==== Parameters - # * details - A list of details to restrict the search by. This - # might include details like the format or locale of the template. - # * require_layout - If this is true, raise an ArgumentError - # with details about the fact that the exception could not be - # found (defaults to false) + # * require_layout - If set to true and layout is not found, + # an ArgumentError exception is raised (defaults to false) # # ==== Returns # * template - The template object for the default layout (or nil) -- cgit v1.2.3 From fd86a1b6b068df87164d5763bdcd4a323a1e76f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 19:06:45 +0000 Subject: Rely on a public contract between railties instead of accessing railtie methods directly. --- actionpack/lib/abstract_controller/railties/routes_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/railties/routes_helpers.rb b/actionpack/lib/abstract_controller/railties/routes_helpers.rb index dec1e9d6d9..6684f46f64 100644 --- a/actionpack/lib/abstract_controller/railties/routes_helpers.rb +++ b/actionpack/lib/abstract_controller/railties/routes_helpers.rb @@ -5,8 +5,8 @@ module AbstractController Module.new do define_method(:inherited) do |klass| super(klass) - if namespace = klass.parents.detect {|m| m.respond_to?(:_railtie) } - klass.send(:include, namespace._railtie.routes.url_helpers) + if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_routes_url_helpers) } + klass.send(:include, namespace.railtie_routes_url_helpers) else klass.send(:include, routes.url_helpers) end -- cgit v1.2.3 From 18ceed201b37d91ad6598d0f8b3c010e6cc48b15 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Tue, 6 Dec 2011 21:05:56 -0500 Subject: Allow layout fallback when using `layout` method Rails will now use your default layout (such as "layouts/application") when you specify a layout with `:only` and `:except` condition, and those conditions fail. For example, consider this snippet: class CarsController layout 'single_car', :only => :show end Rails will use 'layouts/single_car' when a request comes in `:show` action, and use 'layouts/application' (or 'layouts/cars', if exists) when a request comes in for any other actions. --- actionpack/lib/abstract_controller/layouts.rb | 59 +++++++++++++++------------ 1 file changed, 34 insertions(+), 25 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index bbf5efe565..79edd5418e 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -244,42 +244,51 @@ module AbstractController def _write_layout_method remove_possible_method(:_layout) - case defined?(@_layout) ? @_layout : nil - when String - self.class_eval %{def _layout; #{@_layout.inspect} end}, __FILE__, __LINE__ - when Symbol - self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 - def _layout + prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"] + layout_definition = case defined?(@_layout) ? @_layout : nil + when String + @_layout.inspect + when Symbol + <<-RUBY #{@_layout}.tap do |layout| unless layout.is_a?(String) || !layout raise ArgumentError, "Your layout method :#{@_layout} returned \#{layout}. It " \ "should have returned a String, false, or nil" end end - end - ruby_eval - when Proc - define_method :_layout_from_proc, &@_layout - self.class_eval %{def _layout; _layout_from_proc(self) end}, __FILE__, __LINE__ - when false - self.class_eval %{def _layout; end}, __FILE__, __LINE__ - when true - raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil" - when nil - if name - _prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"] - - self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 - def _layout - if template_exists?("#{_implied_layout_name}", #{_prefixes.inspect}) + RUBY + 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 + if name + <<-RUBY + if template_exists?("#{_implied_layout_name}", #{prefixes.inspect}) "#{_implied_layout_name}" else super end + RUBY + end + end + + self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def _layout + if action_has_layout? + #{layout_definition} + elsif self.class.name + if template_exists?("#{_implied_layout_name}", #{prefixes.inspect}) + "#{_implied_layout_name}" + else + super end - RUBY + end end - end + RUBY self.class_eval { private :_layout } end end @@ -337,7 +346,7 @@ module AbstractController # * template - The template object for the default layout (or nil) def _default_layout(require_layout = false) begin - layout_name = _layout if action_has_layout? + layout_name = _layout rescue NameError => e raise e, "Could not render layout: #{e.message}" end -- cgit v1.2.3 From efc28a7f701e518eb747c57712f6c1d8e7027aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 8 Dec 2011 15:23:23 +0100 Subject: Some small optimizations and improvements to benchmark code. --- actionpack/lib/abstract_controller/rendering.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 41fdc11196..d95770c049 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,12 +66,7 @@ module AbstractController end def view_context_class - @_view_context_class || self.class.view_context_class - end - - def initialize(*) - @_view_context_class = nil - super + @_view_context_class ||= self.class.view_context_class end # An instance of a view class. The default view class is ActionView::Base -- cgit v1.2.3 From 239262fee03096d1e52acf8fe69de736726d87e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 8 Dec 2011 16:37:56 +0100 Subject: Optimize layout lookup to avoid double calls. --- actionpack/lib/abstract_controller/layouts.rb | 50 ++++++++++++------------ actionpack/lib/abstract_controller/view_paths.rb | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 79edd5418e..6b6b38c64f 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -168,11 +168,12 @@ module AbstractController included do class_attribute :_layout_conditions remove_possible_method :_layout_conditions - delegate :_layout_conditions, :to => :'self.class' self._layout_conditions = {} _write_layout_method end + delegate :_layout_conditions, :to => "self.class" + module ClassMethods def inherited(klass) super @@ -188,7 +189,7 @@ module AbstractController # # ==== Returns # * Boolean - True if the action has a layout, false otherwise. - def action_has_layout? + def conditional_layout? return unless super conditions = _layout_conditions @@ -244,7 +245,13 @@ module AbstractController def _write_layout_method remove_possible_method(:_layout) - prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"] + prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"] + name_clause = if name + <<-RUBY + lookup_context.find_all("#{_implied_layout_name}", #{prefixes.inspect}).first || super + RUBY + end + layout_definition = case defined?(@_layout) ? @_layout : nil when String @_layout.inspect @@ -265,27 +272,15 @@ module AbstractController when true raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil" when nil - if name - <<-RUBY - if template_exists?("#{_implied_layout_name}", #{prefixes.inspect}) - "#{_implied_layout_name}" - else - super - end - RUBY - end + name_clause end self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def _layout - if action_has_layout? + if conditional_layout? #{layout_definition} - elsif self.class.name - if template_exists?("#{_implied_layout_name}", #{prefixes.inspect}) - "#{_implied_layout_name}" - else - super - end + else + #{name_clause} end end RUBY @@ -298,8 +293,7 @@ module AbstractController if _include_layout?(options) layout = options.key?(:layout) ? options.delete(:layout) : :default - value = _layout_for_option(layout) - options[:layout] = (value =~ /\blayouts/ ? value : "layouts/#{value}") if value + options[:layout] = Proc.new { _normalize_layout(_layout_for_option(layout)) } end end @@ -314,6 +308,10 @@ module AbstractController @_action_has_layout end + def conditional_layout? + true + end + private # This will be overwritten by _write_layout_method @@ -335,6 +333,10 @@ module AbstractController end end + def _normalize_layout(value) + value.is_a?(String) && value !~ /\blayouts/ ? "layouts/#{value}" : value + end + # Returns the default layout for this controller. # Optionally raises an exception if the layout could not be found. # @@ -346,17 +348,17 @@ module AbstractController # * template - The template object for the default layout (or nil) def _default_layout(require_layout = false) begin - layout_name = _layout + value = _layout if action_has_layout? rescue NameError => e raise e, "Could not render layout: #{e.message}" end - if require_layout && action_has_layout? && !layout_name + if require_layout && action_has_layout? && !value raise ArgumentError, "There was no default layout for #{self.class} in #{view_paths.inspect}" end - layout_name + value end def _include_layout?(options) diff --git a/actionpack/lib/abstract_controller/view_paths.rb b/actionpack/lib/abstract_controller/view_paths.rb index e8394447a7..96118b940f 100644 --- a/actionpack/lib/abstract_controller/view_paths.rb +++ b/actionpack/lib/abstract_controller/view_paths.rb @@ -10,7 +10,7 @@ module AbstractController self._view_paths.freeze end - delegate :find_template, :template_exists?, :view_paths, :formats, :formats=, + delegate :template_exists?, :view_paths, :formats, :formats=, :locale, :locale=, :to => :lookup_context module ClassMethods -- cgit v1.2.3 From 67cc07e0c4bd071dd3d2f4098e5a4c31ba590684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 8 Dec 2011 16:51:47 +0100 Subject: Just use the proc if there is a chance of layout lookup. --- actionpack/lib/abstract_controller/layouts.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 6b6b38c64f..8356d822da 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -293,7 +293,7 @@ module AbstractController if _include_layout?(options) layout = options.key?(:layout) ? options.delete(:layout) : :default - options[:layout] = Proc.new { _normalize_layout(_layout_for_option(layout)) } + options[:layout] = _layout_for_option(layout) end end @@ -323,9 +323,10 @@ module AbstractController # * name - The name of the template def _layout_for_option(name) case name - when String then name - when true then _default_layout(true) - when :default then _default_layout(false) + when String then _normalize_layout(name) + when Proc then name + when true then Proc.new { _default_layout(true) } + when :default then Proc.new { _default_layout(false) } when false, nil then nil else raise ArgumentError, @@ -358,7 +359,7 @@ module AbstractController "There was no default layout for #{self.class} in #{view_paths.inspect}" end - value + _normalize_layout(value) end def _include_layout?(options) -- cgit v1.2.3 From 5ad52152117ecda1166359c499bcd03ae6be3365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 9 Dec 2011 07:20:55 +0100 Subject: Deprecate implicit layout lookup in favor of inheriting the _layout config. --- actionpack/lib/abstract_controller/layouts.rb | 118 +++++++++++++++++++------- 1 file changed, 86 insertions(+), 32 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 8356d822da..8b6136d6ba 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -66,27 +66,40 @@ module AbstractController # == Inheritance Examples # # class BankController < ActionController::Base - # layout "bank_standard" + # # bank.html.erb exists + # + # class ExchangeController < BankController + # # exchange.html.erb exists + # + # class CurrencyController < BankController # # class InformationController < BankController + # layout "information" # - # class TellerController < BankController + # class TellerController < InformationController # # teller.html.erb exists # - # class TillController < TellerController + # class EmployeeController < InformationController + # # employee.html.erb exists + # layout nil # # class VaultController < BankController # layout :access_level_layout # - # class EmployeeController < BankController - # layout nil + # class TillController < BankController + # layout false + # + # In these examples, we have three implicit lookup scenrios: + # * The BankController uses the "bank" layout. + # * The ExchangeController uses the "exchange" layout. + # * The CurrencyController inherits the layout from BankController. # - # In these examples: - # * The InformationController uses the "bank_standard" layout, inherited from BankController. - # * The TellerController follows convention and uses +app/views/layouts/teller.html.erb+. - # * The TillController inherits the layout from TellerController and uses +teller.html.erb+ as well. + # However, when a layout is explicitly set, the explicitly set layout wins: + # * The InformationController uses the "information" layout, explicitly set. + # * The TellerController also uses the "information" layout, because the parent explicitly set it. + # * The EmployeeController uses the "employee" layout, because it set the layout to nil, resetting the parent configuration. # * The VaultController chooses a layout dynamically by calling the access_level_layout method. - # * The EmployeeController does not use a layout at all. + # * The TillController does not use a layout at all. # # == Types of layouts # @@ -126,6 +139,22 @@ module AbstractController # If no directory is specified for the template name, the template will by default be looked for in app/views/layouts/. # Otherwise, it will be looked up relative to the template root. # + # Setting the layout to nil forces it to be looked up in the filesystem and fallbacks to the parent behavior if none exists. + # Setting it to nil is useful to re-enable template lookup overriding a previous configuration set in the parent: + # + # class ApplicationController < ActionController::Base + # layout "application" + # end + # + # class PostsController < ApplicationController + # # Will use "application" layout + # end + # + # class CommentsController < ApplicationController + # # Will search for "comments" layout and fallback "application" layout + # layout nil + # end + # # == Conditional layouts # # If you have a layout that by default is applied to all the actions of a controller, you still have the option of rendering @@ -252,28 +281,53 @@ module AbstractController RUBY end - layout_definition = case defined?(@_layout) ? @_layout : nil - when String - @_layout.inspect - when Symbol - <<-RUBY - #{@_layout}.tap do |layout| - unless layout.is_a?(String) || !layout - raise ArgumentError, "Your layout method :#{@_layout} returned \#{layout}. It " \ - "should have returned a String, false, or nil" + if defined?(@_layout) + layout_definition = case @_layout + when String + @_layout.inspect + when Symbol + <<-RUBY + #{@_layout}.tap do |layout| + unless layout.is_a?(String) || !layout + raise ArgumentError, "Your layout method :#{@_layout} returned \#{layout}. It " \ + "should have returned a String, false, or nil" + end end - end - RUBY - 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 + RUBY + 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 + # Add a deprecation if the parent layout was explicitly set and the child + # still does a dynamic lookup. In next Rails release, we should @_layout + # to be inheritable so we can skip the child lookup if the parent explicitly + # set the layout. + 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 + <<-RUBY + if template = lookup_context.find_all("#{_implied_layout_name}", #{prefixes.inspect}).first + ActiveSupport::Deprecation.warn 'Layout found at "#{_implied_layout_name}" for #{name} but parent controller ' \ + 'set layout to #{inspect.inspect}. Please explicitly set your layout to "#{_implied_layout_name}" ' \ + 'or set it to nil to force a dynamic lookup.' + template + else + super + end + RUBY + end + end self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def _layout @@ -283,8 +337,8 @@ module AbstractController #{name_clause} end end + private :_layout RUBY - self.class_eval { private :_layout } end end -- cgit v1.2.3 From ab30570b69e6118bbfbd8dfaa7577668b34e5eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 9 Dec 2011 20:47:33 +0100 Subject: Fix extend -> include. --- actionpack/lib/abstract_controller/logger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/logger.rb b/actionpack/lib/abstract_controller/logger.rb index 0b196119f4..8b36230397 100644 --- a/actionpack/lib/abstract_controller/logger.rb +++ b/actionpack/lib/abstract_controller/logger.rb @@ -7,7 +7,7 @@ module AbstractController included do config_accessor :logger - extend ActiveSupport::Benchmarkable + include ActiveSupport::Benchmarkable end end end -- cgit v1.2.3 From 5266eb9f611a114663c48eec0680b7050181d3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Oko=C5=84ski?= Date: Mon, 12 Dec 2011 16:52:56 +0100 Subject: Default relative_url_root to ENV["RAILS_RELATIVE_URL_ROOT"]. Fixes #3365 --- actionpack/lib/abstract_controller/asset_paths.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/asset_paths.rb b/actionpack/lib/abstract_controller/asset_paths.rb index c2a6809f58..dd5f9a1942 100644 --- a/actionpack/lib/abstract_controller/asset_paths.rb +++ b/actionpack/lib/abstract_controller/asset_paths.rb @@ -4,7 +4,7 @@ module AbstractController included do config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, - :stylesheets_dir, :default_asset_host_protocol + :stylesheets_dir, :default_asset_host_protocol, :relative_url_root end end end -- cgit v1.2.3 From 572c3d517899524c2a7c4c84ad9646660168d4cd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Dec 2011 18:41:37 -0800 Subject: * BufferedLogger is deprecated. Use ActiveSupport::Logger, or the logger from Ruby stdlib. --- actionpack/lib/abstract_controller/logger.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/logger.rb b/actionpack/lib/abstract_controller/logger.rb index 8b36230397..a4e31cd2e5 100644 --- a/actionpack/lib/abstract_controller/logger.rb +++ b/actionpack/lib/abstract_controller/logger.rb @@ -1,4 +1,3 @@ -require "active_support/core_ext/logger" require "active_support/benchmarkable" module AbstractController -- cgit v1.2.3 From cae1768c6a0e3d1cd4a2c2d836ef213438689db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 14:44:48 +0100 Subject: Remove deprecated layout lookup. --- actionpack/lib/abstract_controller/layouts.rb | 72 +++++++++------------------ 1 file changed, 24 insertions(+), 48 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 8b6136d6ba..6a6387632c 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -195,8 +195,9 @@ module AbstractController include Rendering included do - class_attribute :_layout_conditions - remove_possible_method :_layout_conditions + class_attribute :_layout, :_layout_conditions, + :instance_reader => false, :instance_writer => false + self._layout = nil self._layout_conditions = {} _write_layout_method end @@ -254,7 +255,7 @@ module AbstractController conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} } self._layout_conditions = conditions - @_layout = layout || false # Converts nil to false + self._layout = layout _write_layout_method end @@ -281,52 +282,27 @@ module AbstractController RUBY end - if defined?(@_layout) - layout_definition = case @_layout - when String - @_layout.inspect - when Symbol - <<-RUBY - #{@_layout}.tap do |layout| - unless layout.is_a?(String) || !layout - raise ArgumentError, "Your layout method :#{@_layout} returned \#{layout}. It " \ - "should have returned a String, false, or nil" - end + layout_definition = case _layout + when String + _layout.inspect + when Symbol + <<-RUBY + #{_layout}.tap do |layout| + unless layout.is_a?(String) || !layout + raise ArgumentError, "Your layout method :#{_layout} returned \#{layout}. It " \ + "should have returned a String, false, or nil" end - RUBY - 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 - # Add a deprecation if the parent layout was explicitly set and the child - # still does a dynamic lookup. In next Rails release, we should @_layout - # to be inheritable so we can skip the child lookup if the parent explicitly - # set the layout. - 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 - <<-RUBY - if template = lookup_context.find_all("#{_implied_layout_name}", #{prefixes.inspect}).first - ActiveSupport::Deprecation.warn 'Layout found at "#{_implied_layout_name}" for #{name} but parent controller ' \ - 'set layout to #{inspect.inspect}. Please explicitly set your layout to "#{_implied_layout_name}" ' \ - 'or set it to nil to force a dynamic lookup.' - template - else - super - end - RUBY - end + end + RUBY + 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 self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 -- cgit v1.2.3 From e6bfcc21a8b1a139dacc8d6c957bc4ab3e55c3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 09:59:28 +0100 Subject: Remove unecessary config_accessors. --- actionpack/lib/abstract_controller/rendering.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'actionpack/lib/abstract_controller') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index d95770c049..9019c07bca 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -35,7 +35,7 @@ module AbstractController include AbstractController::ViewPaths included do - config_accessor :protected_instance_variables, :instance_reader => false + class_attribute :protected_instance_variables self.protected_instance_variables = [] end @@ -59,12 +59,6 @@ module AbstractController attr_internal_writer :view_context_class - # Explicitly define protected_instance_variables so it can be - # inherited and overwritten by other modules if needed. - def protected_instance_variables - config.protected_instance_variables - end - def view_context_class @_view_context_class ||= self.class.view_context_class end -- cgit v1.2.3