Permalink
Browse files

Remove more dependencies from the view.

  • Loading branch information...
1 parent bebaccd commit 2f683fd870d0e4c5aff38510ef03c7e5144a1ea4 @josevalim josevalim committed May 1, 2011
@@ -202,17 +202,13 @@ def initialize(lookup_context = nil, assigns_for_first_render = {}, controller =
lookup_context : ActionView::LookupContext.new(lookup_context)
@_lookup_context.formats = formats if formats
- @_renderer = ActionView::Renderer.new(@_lookup_context, self)
+ @view_renderer = ActionView::Renderer.new(@_lookup_context, self)
end
def controller_path
@controller_path ||= controller && controller.controller_path
end
- def controller_prefixes
- @controller_prefixes ||= controller && controller._prefixes
- end
-
ActiveSupport.run_load_hooks(:action_view, self)
end
end
@@ -217,9 +217,11 @@ module ActionView
class PartialRenderer < AbstractRenderer #:nodoc:
PARTIAL_NAMES = Hash.new {|h,k| h[k] = {} }
+ # TODO Controller should not come from the view
def initialize(view, *)
super
- @partial_names = PARTIAL_NAMES[@view.controller.class.name]
+ @controller = @view.controller
+ @partial_names = PARTIAL_NAMES[@controller.class.name]
end
def setup(options, block)
@@ -292,7 +294,7 @@ def render_partial
locals[as] = object
content = @template.render(view, locals) do |*name|
- view._block_layout_for(*name, &block)
+ view._layout_for(*name, &block)
end
content = layout.render(view, locals){ content } if layout
@@ -301,6 +303,10 @@ def render_partial
private
+ def controller_prefixes
+ @controller_prefixes ||= @controller && @controller._prefixes
+ end
+
def collection
if @options.key?(:collection)
collection = @options[:collection]
@@ -324,7 +330,7 @@ def find_partial
end
def find_template(path=@path, locals=@locals.keys)
- prefixes = path.include?(?/) ? [] : @view.controller_prefixes
+ prefixes = path.include?(?/) ? [] : controller_prefixes
@lookup_context.find_template(path, prefixes, true, locals)
end
@@ -365,7 +371,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 = @view.controller_prefixes.first
+ path = controller_prefixes.first
partial.insert(0, "#{File.dirname(path)}/") if partial.include?(?/) && path.include?(?/)
end
end
@@ -6,6 +6,7 @@ class Renderer
attr_accessor :lookup_context
# TODO: render_context should not be an initialization parameter
+ # TODO: controller should be received on initialization
def initialize(lookup_context, render_context)
@render_context = render_context
@lookup_context = lookup_context
@@ -4,7 +4,7 @@ module ActionView
# = Action View Rendering
module Rendering
# This is temporary until we remove the renderer dependency from AV.
- delegate :render, :render_body, :to => :@_renderer
+ delegate :render, :render_body, :to => :@view_renderer
# Returns the contents that are yielded to a layout, given a name or a block.
#
@@ -52,20 +52,15 @@ module Rendering
# Hello David
# </html>
#
- def _layout_for(*args)
- name = args.first
- name = :layout unless name.is_a?(Symbol)
- @_view_flow.get(name).html_safe
- end
-
- # Handle layout for calls from partials that supports blocks.
- def _block_layout_for(*args, &block)
+ def _layout_for(*args, &block)
name = args.first
- if !name.is_a?(Symbol) && block
+ if name.is_a?(Symbol)
+ @_view_flow.get(name).html_safe
+ elsif block
capture(*args, &block)
else
- _layout_for(*args)
+ @_view_flow.get(:layout).html_safe
end
end
end
@@ -9,7 +9,9 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
def setup
super
@old_logger = ActionController::Base.logger
- @view = ActionView::Base.new(ActionController::Base.view_paths, {})
+ @controller = Object.new
+ @controller.stubs(:_prefixes).returns(%w(test))
+ @view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH))
ActionView::LogSubscriber.attach_to :action_view
end
@@ -57,7 +59,6 @@ def test_render_partial_template
end
def test_render_partial_with_implicit_path
- @view.stubs(:controller_prefixes).returns(%w(test))
@view.render(Customer.new("david"), :greeting => "hi")
wait
@@ -74,7 +75,6 @@ def test_render_collection_template
end
def test_render_collection_with_implicit_path
- @view.stubs(:controller_prefixes).returns(%w(test))
@view.render([ Customer.new("david"), Customer.new("mary") ], :greeting => "hi")
wait
@@ -83,7 +83,6 @@ def test_render_collection_with_implicit_path
end
def test_render_collection_template_without_path
- @view.stubs(:controller_prefixes).returns(%w(test))
@view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi")
wait

0 comments on commit 2f683fd

Please sign in to comment.