Permalink
Browse files

no @controller dependency in Renderers.

  • Loading branch information...
1 parent b4bc2c5 commit eb327c1bab918c7d9ab723550f767529771d2e19 @apotonick apotonick committed May 3, 2011
@@ -104,7 +104,7 @@ def view_context
# 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
@@ -199,8 +199,9 @@ def initialize(context = nil, assigns_for_first_render = {}, controller = nil, f
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
@@ -3,9 +3,8 @@ class AbstractRenderer #:nodoc:
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
@@ -219,7 +219,7 @@ class PartialRenderer < AbstractRenderer #:nodoc:
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 @@ def setup(context, options, block)
self
end
- def controller_prefixes
- @controller_prefixes ||= @controller && @controller._prefixes
- end
-
def collection
if @options.key?(:collection)
collection = @options[:collection]
@@ -331,7 +327,7 @@ def find_partial
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 @@ def partial_path(object = @object)
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
@@ -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 @@ def render_body(context, options)
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 @@ def render_partial(context, options, &block) #:nodoc:
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
+end

0 comments on commit eb327c1

Please sign in to comment.