diff options
author | José Valim <jose.valim@gmail.com> | 2010-03-08 02:04:18 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-03-08 02:04:18 +0100 |
commit | ffd8d753f171a33cb0f8dadaff7fc5ba12b8f6b0 (patch) | |
tree | fca50e828f91520f2e99323eff90e1bbc81bea7d /actionpack/lib/abstract_controller | |
parent | c7564d74e8a9b451f9fc78566ab0c734671f9612 (diff) | |
download | rails-ffd8d753f171a33cb0f8dadaff7fc5ba12b8f6b0.tar.gz rails-ffd8d753f171a33cb0f8dadaff7fc5ba12b8f6b0.tar.bz2 rails-ffd8d753f171a33cb0f8dadaff7fc5ba12b8f6b0.zip |
Move layout lookup to views.
Diffstat (limited to 'actionpack/lib/abstract_controller')
-rw-r--r-- | actionpack/lib/abstract_controller/base.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/abstract_controller/compatibility.rb | 18 | ||||
-rw-r--r-- | actionpack/lib/abstract_controller/layouts.rb | 25 | ||||
-rw-r--r-- | actionpack/lib/abstract_controller/rendering.rb | 8 |
4 files changed, 11 insertions, 46 deletions
diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index ea88a2d24d..c12b584144 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -7,7 +7,6 @@ module AbstractController class Base attr_internal :response_body attr_internal :action_name - attr_internal :formats class << self attr_reader :abstract @@ -100,11 +99,6 @@ module AbstractController abstract! - # Initialize controller with nil formats. - def initialize #:nodoc: - @_formats = nil - end - def config @config ||= ActiveSupport::InheritableOptions.new(self.class.config) end diff --git a/actionpack/lib/abstract_controller/compatibility.rb b/actionpack/lib/abstract_controller/compatibility.rb deleted file mode 100644 index 85fb1364b7..0000000000 --- a/actionpack/lib/abstract_controller/compatibility.rb +++ /dev/null @@ -1,18 +0,0 @@ -module AbstractController - module Compatibility - extend ActiveSupport::Concern - - def _find_layout(name, details) - details[:prefix] = nil if name =~ /\blayouts/ - super - end - - # Move this into a "don't run in production" module - def _default_layout(details, require_layout = false) - super - rescue ActionView::MissingTemplate - _layout_for_name(_layout({}), {}) - nil - end - end -end diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index c26593dd19..ac0f646e19 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -260,9 +260,11 @@ module AbstractController raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil" when nil if name + _prefix = "layouts" unless _implied_layout_name =~ /\blayouts/ + self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def _layout(details) - if template_exists?("#{_implied_layout_name}", :_prefix => "layouts") + if template_exists?("#{_implied_layout_name}", :_prefix => #{_prefix.inspect}) "#{_implied_layout_name}" else super @@ -290,6 +292,7 @@ module AbstractController # render_template if layout layout = _layout_for_option(layout, options[:_template].details) + layout = find_template(layout, {}) response = layout.render(view_context, options[:locals] || {}) { response } end @@ -309,7 +312,7 @@ module AbstractController # the lookup to. By default, layout lookup is limited to the # formats specified for the current request. def _layout_for_name(name, details) - name && _find_layout(name, details) + name end # Determine the layout for a given name and details, taking into account @@ -337,23 +340,7 @@ module AbstractController return unless (options.keys & [:text, :inline, :partial]).empty? || options.key?(:layout) layout = options.key?(:layout) ? options[:layout] : :default - options[:_layout] = _layout_for_option(layout, options[:_template].details) - end - - # Take in the name and details and find a Template. - # - # ==== Parameters - # name<String>:: The name of the template to retrieve - # details<Hash>:: A list of details to restrict the search by. This - # might include details like the format or locale of the template. - # - # ==== Returns - # Template:: A template object matching the name and details - def _find_layout(name, details) - prefix = details.key?(:prefix) ? details.delete(:prefix) : "layouts" - # TODO This should happen automatically - template_lookup.details = template_lookup.details.merge(:formats => details[:formats]) - find_template(name, :_prefix => prefix) + options[:layout] = _layout_for_option(layout, options[:_template].details) end # Returns the default layout for this controller and a given set of details. diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index df33e8b480..8125badc75 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -15,10 +15,12 @@ module AbstractController included do class_attribute :_view_paths - delegate :_view_paths, :to => :'self.class' self._view_paths = ActionView::PathSet.new end + delegate :formats, :formats=, :to => :template_lookup + delegate :_view_paths, :to => :'self.class' + # An instance of a view class. The default view class is ActionView::Base # # The view class must have the following methods: @@ -180,11 +182,11 @@ module AbstractController end def details_for_render - { :formats => formats, :locale => [I18n.locale] } + { } end def _normalize_details(options) - details = details_for_render + details = template_lookup.details details[:formats] = Array(options[:format]) if options[:format] details[:locale] = Array(options[:locale]) if options[:locale] details |