aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-01 12:16:31 +0200
committerJosé Valim <jose.valim@gmail.com>2011-05-01 13:40:12 +0200
commit33cc001f9158463389a9c9c321de0dbdccb1df8d (patch)
tree04b804f786fd8a982926bb2d1d9a1882cc6b19da
parent2f683fd870d0e4c5aff38510ef03c7e5144a1ea4 (diff)
downloadrails-33cc001f9158463389a9c9c321de0dbdccb1df8d.tar.gz
rails-33cc001f9158463389a9c9c321de0dbdccb1df8d.tar.bz2
rails-33cc001f9158463389a9c9c321de0dbdccb1df8d.zip
More cleanup and moving responsibilities around.
-rw-r--r--actionpack/lib/action_view.rb1
-rw-r--r--actionpack/lib/action_view/base.rb19
-rw-r--r--actionpack/lib/action_view/context.rb84
-rw-r--r--actionpack/lib/action_view/flows.rb2
-rw-r--r--actionpack/lib/action_view/helpers/capture_helper.rb6
-rw-r--r--actionpack/lib/action_view/renderer/streaming_template_renderer.rb4
-rw-r--r--actionpack/lib/action_view/renderer/template_renderer.rb2
-rw-r--r--actionpack/lib/action_view/rendering.rb67
-rw-r--r--actionpack/test/template/capture_helper_test.rb10
9 files changed, 83 insertions, 112 deletions
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index 69c50a056c..92b6f7c770 100644
--- a/actionpack/lib/action_view.rb
+++ b/actionpack/lib/action_view.rb
@@ -35,7 +35,6 @@ module ActionView
autoload :Helpers
autoload :LookupContext
autoload :PathSet
- autoload :Rendering
autoload :Template
autoload :TestCase
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 37cd4d9ddc..cde1c36bd9 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -131,7 +131,7 @@ module ActionView #:nodoc:
#
# More builder documentation can be found at http://builder.rubyforge.org.
class Base
- include Helpers, Rendering, ::ERB::Util, Context
+ include Helpers, ::ERB::Util, Context
# Specify the proc used to decorate input tags that refer to attributes with errors.
cattr_accessor :field_error_proc
@@ -159,10 +159,10 @@ module ActionView #:nodoc:
end
end
- attr_accessor :_view_flow
- attr_internal :request, :controller, :config, :assigns, :lookup_context
+ attr_accessor :view_renderer
+ attr_internal :request, :controller, :config, :assigns
- # TODO Consider removing those setters once we have the renderer in place.
+ delegate :lookup_context, :render, :render_body, :to => :view_renderer
delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, :to => :lookup_context
delegate :request_forgery_protection_token, :params, :session, :cookies, :response, :headers,
@@ -187,22 +187,21 @@ module ActionView #:nodoc:
assign(assigns_for_first_render)
self.helpers = Module.new unless self.class.helpers
- @_config = {}
- @_virtual_path = nil
- @_view_flow = OutputFlow.new
+ @view_flow = OutputFlow.new
@output_buffer = nil
@virtual_path = nil
+ @_config = {}
if @_controller = controller
@_request = controller.request if controller.respond_to?(:request)
@_config = controller.config.inheritable_copy if controller.respond_to?(:config)
end
- @_lookup_context = lookup_context.is_a?(ActionView::LookupContext) ?
+ _lookup_context = lookup_context.is_a?(ActionView::LookupContext) ?
lookup_context : ActionView::LookupContext.new(lookup_context)
- @_lookup_context.formats = formats if formats
+ _lookup_context.formats = formats if formats
- @view_renderer = ActionView::Renderer.new(@_lookup_context, self)
+ @view_renderer = ActionView::Renderer.new(_lookup_context, self)
end
def controller_path
diff --git a/actionpack/lib/action_view/context.rb b/actionpack/lib/action_view/context.rb
index 710cdc613d..c4bebd7d95 100644
--- a/actionpack/lib/action_view/context.rb
+++ b/actionpack/lib/action_view/context.rb
@@ -8,29 +8,69 @@ module ActionView
# Action View contexts are supplied to Action Controller to render template.
# The default Action View context is ActionView::Base.
#
- # In order to work with ActionController, a Context must implement:
- #
- # Context#render_partial[options]
- # - responsible for setting options[:_template]
- # - Returns String with the rendered partial
- # options<Hash>:: see _render_partial in ActionView::Base
- # Context#render_template[template, layout, options, partial]
- # - Returns String with the rendered template
- # template<ActionView::Template>:: The template to render
- # layout<ActionView::Template>:: The layout to render around the template
- # options<Hash>:: See _render_template_with_layout in ActionView::Base
- # partial<Boolean>:: Whether or not the template to render is a partial
- #
- # An Action View context can also mix in Action View's helpers. In order to
- # mix in helpers, a context must implement:
- #
- # Context#controller
- # - Returns an instance of AbstractController
- #
- # In any case, a context must mix in ActionView::Context, which stores compiled
- # template and provides the output buffer.
+ # In order to work with ActionController, a Context must just include this module.
module Context
include CompiledTemplates
- attr_accessor :output_buffer, :view_renderer, :view_flow
+ attr_accessor :output_buffer, :view_flow
+
+ # Returns the contents that are yielded to a layout, given a name or a block.
+ #
+ # You can think of a layout as a method that is called with a block. If the user calls
+ # <tt>yield :some_name</tt>, the block, by default, returns <tt>content_for(:some_name)</tt>.
+ # If the user calls simply +yield+, the default block returns <tt>content_for(:layout)</tt>.
+ #
+ # The user can override this default by passing a block to the layout:
+ #
+ # # The template
+ # <%= render :layout => "my_layout" do %>
+ # Content
+ # <% end %>
+ #
+ # # The layout
+ # <html>
+ # <%= yield %>
+ # </html>
+ #
+ # In this case, instead of the default block, which would return <tt>content_for(:layout)</tt>,
+ # this method returns the block that was passed in to <tt>render :layout</tt>, and the response
+ # would be
+ #
+ # <html>
+ # Content
+ # </html>
+ #
+ # Finally, the block can take block arguments, which can be passed in by +yield+:
+ #
+ # # The template
+ # <%= render :layout => "my_layout" do |customer| %>
+ # Hello <%= customer.name %>
+ # <% end %>
+ #
+ # # The layout
+ # <html>
+ # <%= yield Struct.new(:name).new("David") %>
+ # </html>
+ #
+ # In this case, the layout would receive the block passed into <tt>render :layout</tt>,
+ # and the struct specified would be passed into the block as an argument. The result
+ # would be
+ #
+ # <html>
+ # Hello David
+ # </html>
+ #
+ def _layout_for(*args, &block)
+ name = args.first
+
+ if name.is_a?(Symbol)
+ view_flow.get(name).html_safe
+ elsif block
+ # TODO Import capture into AV::Context or
+ # leave it as implicit dependency?
+ capture(*args, &block)
+ else
+ view_flow.get(:layout).html_safe
+ end
+ end
end
end \ No newline at end of file
diff --git a/actionpack/lib/action_view/flows.rb b/actionpack/lib/action_view/flows.rb
index 386a06511f..a8f740713f 100644
--- a/actionpack/lib/action_view/flows.rb
+++ b/actionpack/lib/action_view/flows.rb
@@ -34,7 +34,7 @@ module ActionView
@view = view
@parent = nil
@child = view.output_buffer
- @content = view._view_flow.content
+ @content = view.view_flow.content
@fiber = fiber
@root = Fiber.current.object_id
end
diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb
index 0139714240..ead7feb091 100644
--- a/actionpack/lib/action_view/helpers/capture_helper.rb
+++ b/actionpack/lib/action_view/helpers/capture_helper.rb
@@ -135,7 +135,7 @@ module ActionView
# for elements that will be fragment cached.
def content_for(name, content = nil, &block)
content = capture(&block) if block_given?
- result = @_view_flow.append(name, content) if content
+ result = @view_flow.append(name, content) if content
result unless content
end
@@ -146,7 +146,7 @@ module ActionView
# the layout to stop looking for more contents.
def provide(name, content = nil, &block)
content = capture(&block) if block_given?
- result = @_view_flow.append!(name, content) if content
+ result = @view_flow.append!(name, content) if content
result unless content
end
@@ -169,7 +169,7 @@ module ActionView
# </body>
# </html>
def content_for?(name)
- @_view_flow.get(name).present?
+ @view_flow.get(name).present?
end
# Use an alternate output buffer for the duration of the block.
diff --git a/actionpack/lib/action_view/renderer/streaming_template_renderer.rb b/actionpack/lib/action_view/renderer/streaming_template_renderer.rb
index 03aab444f8..d60b42a284 100644
--- a/actionpack/lib/action_view/renderer/streaming_template_renderer.rb
+++ b/actionpack/lib/action_view/renderer/streaming_template_renderer.rb
@@ -106,7 +106,7 @@ module ActionView
# Set the view flow to support streaming. It will be aware
# when to stop rendering the layout because it needs to search
# something in the template and vice-versa.
- view._view_flow = StreamingFlow.new(view, fiber)
+ view.view_flow = StreamingFlow.new(view, fiber)
# Yo! Start the fiber!
fiber.resume
@@ -118,7 +118,7 @@ module ActionView
content = template.render(view, locals, &yielder)
# Once rendering the template is done, sets its content in the :layout key.
- view._view_flow.set(:layout, content)
+ view.view_flow.set(:layout, content)
# In case the layout continues yielding, we need to resume
# the fiber until all yields are handled.
diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb
index 6b5ead463f..471428ac9e 100644
--- a/actionpack/lib/action_view/renderer/template_renderer.rb
+++ b/actionpack/lib/action_view/renderer/template_renderer.rb
@@ -46,7 +46,7 @@ module ActionView
if layout
view = @view
- view._view_flow.set(:layout, content)
+ view.view_flow.set(:layout, content)
layout.render(view, locals){ |*name| view._layout_for(*name) }
else
content
diff --git a/actionpack/lib/action_view/rendering.rb b/actionpack/lib/action_view/rendering.rb
deleted file mode 100644
index 9850965456..0000000000
--- a/actionpack/lib/action_view/rendering.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-require 'active_support/core_ext/object/try'
-
-module ActionView
- # = Action View Rendering
- module Rendering
- # This is temporary until we remove the renderer dependency from AV.
- delegate :render, :render_body, :to => :@view_renderer
-
- # Returns the contents that are yielded to a layout, given a name or a block.
- #
- # You can think of a layout as a method that is called with a block. If the user calls
- # <tt>yield :some_name</tt>, the block, by default, returns <tt>content_for(:some_name)</tt>.
- # If the user calls simply +yield+, the default block returns <tt>content_for(:layout)</tt>.
- #
- # The user can override this default by passing a block to the layout:
- #
- # # The template
- # <%= render :layout => "my_layout" do %>
- # Content
- # <% end %>
- #
- # # The layout
- # <html>
- # <%= yield %>
- # </html>
- #
- # In this case, instead of the default block, which would return <tt>content_for(:layout)</tt>,
- # this method returns the block that was passed in to <tt>render :layout</tt>, and the response
- # would be
- #
- # <html>
- # Content
- # </html>
- #
- # Finally, the block can take block arguments, which can be passed in by +yield+:
- #
- # # The template
- # <%= render :layout => "my_layout" do |customer| %>
- # Hello <%= customer.name %>
- # <% end %>
- #
- # # The layout
- # <html>
- # <%= yield Struct.new(:name).new("David") %>
- # </html>
- #
- # In this case, the layout would receive the block passed into <tt>render :layout</tt>,
- # and the struct specified would be passed into the block as an argument. The result
- # would be
- #
- # <html>
- # Hello David
- # </html>
- #
- def _layout_for(*args, &block)
- name = args.first
-
- if name.is_a?(Symbol)
- @_view_flow.get(name).html_safe
- elsif block
- capture(*args, &block)
- else
- @_view_flow.get(:layout).html_safe
- end
- end
- end
-end
diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb
index a9a36e6e6b..592c7da060 100644
--- a/actionpack/test/template/capture_helper_test.rb
+++ b/actionpack/test/template/capture_helper_test.rb
@@ -4,7 +4,7 @@ class CaptureHelperTest < ActionView::TestCase
def setup
super
@av = ActionView::Base.new
- @_view_flow = ActionView::OutputFlow.new
+ @view_flow = ActionView::OutputFlow.new
end
def test_capture_captures_the_temporary_output_buffer_in_its_block
@@ -49,14 +49,14 @@ class CaptureHelperTest < ActionView::TestCase
assert !content_for?(:title)
provide :title, "hi"
assert content_for?(:title)
- assert_equal "hi", @_view_flow.get(:title)
+ assert_equal "hi", @view_flow.get(:title)
provide :title, "<p>title</p>"
- assert_equal "hi&lt;p&gt;title&lt;/p&gt;", @_view_flow.get(:title)
+ assert_equal "hi&lt;p&gt;title&lt;/p&gt;", @view_flow.get(:title)
- @_view_flow = ActionView::OutputFlow.new
+ @view_flow = ActionView::OutputFlow.new
provide :title, "hi"
provide :title, "<p>title</p>".html_safe
- assert_equal "hi<p>title</p>", @_view_flow.get(:title)
+ assert_equal "hi<p>title</p>", @view_flow.get(:title)
end
def test_with_output_buffer_swaps_the_output_buffer_given_no_argument