aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/abstract_controller/base.rb6
-rw-r--r--actionpack/lib/abstract_controller/compatibility.rb18
-rw-r--r--actionpack/lib/abstract_controller/layouts.rb25
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb8
-rw-r--r--actionpack/lib/action_controller/metal/implicit_render.rb3
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb2
-rw-r--r--actionpack/lib/action_view/base.rb6
-rw-r--r--actionpack/lib/action_view/render/partials.rb2
-rw-r--r--actionpack/lib/action_view/render/rendering.rb16
-rw-r--r--actionpack/lib/action_view/template/lookup.rb8
10 files changed, 38 insertions, 56 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
diff --git a/actionpack/lib/action_controller/metal/implicit_render.rb b/actionpack/lib/action_controller/metal/implicit_render.rb
index da717fcce2..c3e3b8fdf5 100644
--- a/actionpack/lib/action_controller/metal/implicit_render.rb
+++ b/actionpack/lib/action_controller/metal/implicit_render.rb
@@ -12,8 +12,7 @@ module ActionController
def method_for_action(action_name)
super || begin
- # TODO This should use template lookup
- if view_paths.exists?(action_name.to_s, details_for_render, controller_path)
+ if template_exists?(action_name.to_s, :_prefix => controller_path)
"default_render"
end
end
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index 0a4215028b..e2d2e2312b 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -5,7 +5,7 @@ module ActionController
include ActionController::RackDelegation
include AbstractController::Rendering
- def process_action(*)
+ def process(*)
self.formats = request.formats.map {|x| x.to_sym }
super
end
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 22bc390dc5..5acd2a8b82 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -263,11 +263,7 @@ module ActionView #:nodoc:
attr_internal :controller, :template, :config
attr_reader :template_lookup
- delegate :find, :view_paths, :view_paths=, :to => :template_lookup
-
- def formats=(formats)
- update_details(:formats => Array(formats))
- end
+ delegate :find, :formats, :formats=, :view_paths, :view_paths=, :to => :template_lookup
def update_details(details)
old_details = template_lookup.details
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index 74513935a7..52cb188508 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -330,7 +330,7 @@ module ActionView
details = options[:_details]
# TODO This should happen automatically as well
- self.formats = details[:formats] if details
+ self.formats = details[:formats] if details[:formats]
renderer = PartialRenderer.new(self, options, nil)
text = renderer.render
options[:_template] = renderer.template
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index 1be5675e37..b92a03ddbd 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -88,12 +88,26 @@ module ActionView
# _layout:: The layout, if any, to wrap the Template in
def render_template(options)
_evaluate_assigns_and_ivars
- template, layout = options.values_at(:_template, :_layout)
+ template, layout = options.values_at(:_template, :layout)
_render_template(template, layout, options)
end
+ def _find_layout(template, layout)
+ begin
+ prefix = "layouts" unless layout =~ /\blayouts/
+ layout = find(layout, prefix)
+ rescue ActionView::MissingTemplate => e
+ update_details(:formats => nil) do
+ raise unless template_lookup.exists?(layout, prefix)
+ end
+ end
+ end
+
def _render_template(template, layout = nil, options = {})
+ self.formats = template.details[:formats]
+
locals = options[:locals] || {}
+ layout = _find_layout(template, layout) if layout.is_a?(String)
ActiveSupport::Notifications.instrument("action_view.render_template",
:identifier => template.identifier, :layout => layout.try(:identifier)) do
diff --git a/actionpack/lib/action_view/template/lookup.rb b/actionpack/lib/action_view/template/lookup.rb
index ea3a12615b..30de093934 100644
--- a/actionpack/lib/action_view/template/lookup.rb
+++ b/actionpack/lib/action_view/template/lookup.rb
@@ -23,6 +23,14 @@ module ActionView
self.view_paths = view_paths
end
+ def formats
+ @details[:formats]
+ end
+
+ def formats=(value)
+ self.details = @details.merge(:formats => Array(value))
+ end
+
def view_paths=(paths)
@view_paths = ActionView::Base.process_view_paths(paths)
end