aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-04 08:37:59 +0200
committerJosé Valim <jose.valim@gmail.com>2011-05-04 08:37:59 +0200
commit4758d37044ac7a938c8b1dbd90470410a0566491 (patch)
tree3a3aedaec37ea8ef02b6e99f104b4f1fc2f721e7
parentbff374050d5a7e237fda98a1d4cc6256484e94f2 (diff)
parenteb327c1bab918c7d9ab723550f767529771d2e19 (diff)
downloadrails-4758d37044ac7a938c8b1dbd90470410a0566491.tar.gz
rails-4758d37044ac7a938c8b1dbd90470410a0566491.tar.bz2
rails-4758d37044ac7a938c8b1dbd90470410a0566491.zip
Merge remote branch 'apotonick/presentation'
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb2
-rw-r--r--actionpack/lib/abstract_controller/view_paths.rb7
-rw-r--r--actionpack/lib/action_view/base.rb5
-rw-r--r--actionpack/lib/action_view/lookup_context.rb3
-rw-r--r--actionpack/lib/action_view/renderer/abstract_renderer.rb3
-rw-r--r--actionpack/lib/action_view/renderer/partial_renderer.rb10
-rw-r--r--actionpack/lib/action_view/renderer/renderer.rb13
-rw-r--r--actionpack/test/controller/view_paths_test.rb4
-rw-r--r--actionpack/test/template/lookup_context_test.rb6
9 files changed, 32 insertions, 21 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 7f1a790ecc..8789168ca7 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -104,7 +104,7 @@ module AbstractController
# Returns an object that is able to render templates.
def view_renderer
- @view_renderer ||= ActionView::Renderer.new(lookup_context, self)
+ @view_renderer ||= ActionView::Renderer.new(lookup_context)
end
# Normalize arguments, options and then delegates render_to_body and
diff --git a/actionpack/lib/abstract_controller/view_paths.rb b/actionpack/lib/abstract_controller/view_paths.rb
index cea0f5ad1e..4fdca2cc5c 100644
--- a/actionpack/lib/abstract_controller/view_paths.rb
+++ b/actionpack/lib/abstract_controller/view_paths.rb
@@ -15,7 +15,10 @@ module AbstractController
# templates, i.e. view paths and details. Check ActionView::LookupContext for more
# information.
def lookup_context
- @lookup_context ||= ActionView::LookupContext.new(self.class._view_paths, details_for_lookup)
+ @lookup_context ||=
+ ActionView::LookupContext.new(self.class._view_paths, details_for_lookup).tap do |ctx|
+ ctx.prefixes = _prefixes
+ end
end
def details_for_lookup
@@ -67,4 +70,4 @@ module AbstractController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index ca0a89c8a5..db3c83d028 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -199,8 +199,9 @@ module ActionView #:nodoc:
elsif
lookup_context = context.is_a?(ActionView::LookupContext) ?
context : ActionView::LookupContext.new(context)
- lookup_context.formats = formats if formats
- @view_renderer = ActionView::Renderer.new(lookup_context, controller)
+ lookup_context.formats = formats if formats
+ lookup_context.prefixes = controller._prefixes if controller
+ @view_renderer = ActionView::Renderer.new(lookup_context)
end
_prepare_context
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb
index 06c607931d..797a55b2b6 100644
--- a/actionpack/lib/action_view/lookup_context.rb
+++ b/actionpack/lib/action_view/lookup_context.rb
@@ -9,6 +9,8 @@ module ActionView
# generate a key, given to view paths, used in the resolver cache lookup. Since
# this key is generated just once during the request, it speeds up all cache accesses.
class LookupContext #:nodoc:
+ attr_accessor :prefixes
+
mattr_accessor :fallbacks
@@fallbacks = FallbackFileSystemResolver.instances
@@ -62,6 +64,7 @@ module ActionView
@details, @details_key = { :handlers => default_handlers }, nil
@frozen_formats, @skip_default_locale = false, false
@cache = true
+ @prefixes = []
self.view_paths = view_paths
self.registered_detail_setters.each do |key, setter|
diff --git a/actionpack/lib/action_view/renderer/abstract_renderer.rb b/actionpack/lib/action_view/renderer/abstract_renderer.rb
index d389105a7a..60c527beeb 100644
--- a/actionpack/lib/action_view/renderer/abstract_renderer.rb
+++ b/actionpack/lib/action_view/renderer/abstract_renderer.rb
@@ -3,9 +3,8 @@ module ActionView
delegate :find_template, :template_exists?, :with_fallbacks, :update_details,
:with_layout_format, :formats, :freeze_formats, :to => :@lookup_context
- def initialize(lookup_context, controller)
+ def initialize(lookup_context)
@lookup_context = lookup_context
- @controller = controller
end
def render
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index 70327b16c4..a351fbc04f 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -219,7 +219,7 @@ module ActionView
def initialize(*)
super
- @partial_names = PARTIAL_NAMES[@controller.class.name]
+ @partial_names = PARTIAL_NAMES[@lookup_context.prefixes.first]
end
def render(context, options, block)
@@ -304,10 +304,6 @@ module ActionView
self
end
- def controller_prefixes
- @controller_prefixes ||= @controller && @controller._prefixes
- end
-
def collection
if @options.key?(:collection)
collection = @options[:collection]
@@ -331,7 +327,7 @@ module ActionView
end
def find_template(path=@path, locals=@locals.keys)
- prefixes = path.include?(?/) ? [] : controller_prefixes
+ prefixes = path.include?(?/) ? [] : @lookup_context.prefixes
@lookup_context.find_template(path, prefixes, true, locals)
end
@@ -372,7 +368,7 @@ module ActionView
object = object.to_model if object.respond_to?(:to_model)
object.class.model_name.partial_path.dup.tap do |partial|
- path = controller_prefixes.first
+ path = @lookup_context.prefixes.first
partial.insert(0, "#{File.dirname(path)}/") if partial.include?(?/) && path.include?(?/)
end
end
diff --git a/actionpack/lib/action_view/renderer/renderer.rb b/actionpack/lib/action_view/renderer/renderer.rb
index 1fa51d276f..bf1b5a7d22 100644
--- a/actionpack/lib/action_view/renderer/renderer.rb
+++ b/actionpack/lib/action_view/renderer/renderer.rb
@@ -3,11 +3,10 @@ module ActionView
# to other objects like TemplateRenderer and PartialRenderer which
# actually renders the template.
class Renderer
- attr_accessor :lookup_context, :controller
+ attr_accessor :lookup_context
- def initialize(lookup_context, controller)
+ def initialize(lookup_context)
@lookup_context = lookup_context
- @controller = controller
end
# Main render entry point shared by AV and AC.
@@ -28,7 +27,7 @@ module ActionView
if options.key?(:partial)
[render_partial(context, options)]
else
- StreamingTemplateRenderer.new(@lookup_context, @controller).render(context, options)
+ StreamingTemplateRenderer.new(@lookup_context).render(context, options)
end
end
@@ -45,11 +44,11 @@ module ActionView
private
def _template_renderer #:nodoc:
- @_template_renderer ||= TemplateRenderer.new(@lookup_context, @controller)
+ @_template_renderer ||= TemplateRenderer.new(@lookup_context)
end
def _partial_renderer #:nodoc:
- @_partial_renderer ||= PartialRenderer.new(@lookup_context, @controller)
+ @_partial_renderer ||= PartialRenderer.new(@lookup_context)
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 42356be1ea..3de1849db8 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -179,4 +179,8 @@ class ViewLoadPathsTest < ActionController::TestCase
assert_nothing_raised { C.append_view_path 'c/path' }
assert_paths C, "c/path"
end
+
+ def test_lookup_context_accessor
+ assert_equal ["test"], TestController.new.lookup_context.prefixes
+ end
end
diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb
index ff94cba59f..5fb1fdc044 100644
--- a/actionpack/test/template/lookup_context_test.rb
+++ b/actionpack/test/template/lookup_context_test.rb
@@ -180,6 +180,12 @@ class LookupContextTest < ActiveSupport::TestCase
assert_not_equal template, old_template
end
+
+ test "responds to #prefixes" do
+ assert_equal [], @lookup_context.prefixes
+ @lookup_context.prefixes = ["foo"]
+ assert_equal ["foo"], @lookup_context.prefixes
+ end
end
class LookupContextWithFalseCaching < ActiveSupport::TestCase