From 0bdb7d353b4ac6f5470884360f9a480a16bd709c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 2 Jun 2008 13:32:58 -0700 Subject: Work with @output_buffer instead of _erbout --- actionpack/lib/action_view/base.rb | 11 +++++++---- actionpack/lib/action_view/helpers/capture_helper.rb | 18 +++++++++++++----- .../lib/action_view/template_handlers/builder.rb | 7 ++++--- actionpack/lib/action_view/template_handlers/erb.rb | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 5fae2d4dd6..7a603f150f 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -156,10 +156,12 @@ module ActionView #:nodoc: attr_reader :finder attr_accessor :base_path, :assigns, :template_extension, :first_render attr_accessor :controller - + attr_writer :template_format attr_accessor :current_render_extension + attr_accessor :output_buffer + # Specify trim mode for the ERB compiler. Defaults to '-'. # See ERb documentation for suitable values. @@erb_trim_mode = '-' @@ -313,9 +315,10 @@ If you are rendering a subtemplate, you must now use controller-like partial syn private def wrap_content_for_layout(content) - original_content_for_layout = @content_for_layout - @content_for_layout = content - returning(yield) { @content_for_layout = original_content_for_layout } + original_content_for_layout, @content_for_layout = @content_for_layout, content + yield + ensure + @content_for_layout = original_content_for_layout end # Evaluate the local assigns and pushes them to the view. diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index f9a73a4c8d..837305d96c 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -31,11 +31,11 @@ module ActionView # # def capture(*args, &block) - @output_buffer, old_buffer = '', @output_buffer - yield *args - @output_buffer - ensure - @output_buffer = old_buffer + if @output_buffer + with_temporary_output_buffer { yield *args } + else + block.call(*args) + end end # Calling content_for stores a block of markup in an identifier for later use. @@ -119,6 +119,14 @@ module ActionView end private + def with_temporary_output_buffer + @output_buffer, old_buffer = '', @output_buffer + yield + @output_buffer + ensure + @output_buffer = old_buffer + end + def erb_content_for(name, &block) ivar = "@content_for_#{name}" instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{capture(&block)}") diff --git a/actionpack/lib/action_view/template_handlers/builder.rb b/actionpack/lib/action_view/template_handlers/builder.rb index f76d89777a..ee02ce1a6f 100644 --- a/actionpack/lib/action_view/template_handlers/builder.rb +++ b/actionpack/lib/action_view/template_handlers/builder.rb @@ -11,10 +11,11 @@ module ActionView def compile(template) content_type_handler = (@view.send!(:controller).respond_to?(:response) ? "controller.response" : "controller") + "#{content_type_handler}.content_type ||= Mime::XML\n" + - "xml = ::Builder::XmlMarkup.new(:indent => 2)\n" + - template.source + - "\nxml.target!\n" + "xml = ::Builder::XmlMarkup.new(:indent => 2)\n" + + template.source + + "\nxml.target!\n" end def cache_fragment(block, name = {}, options = nil) diff --git a/actionpack/lib/action_view/template_handlers/erb.rb b/actionpack/lib/action_view/template_handlers/erb.rb index d1416b89d1..ad4ccc7c42 100644 --- a/actionpack/lib/action_view/template_handlers/erb.rb +++ b/actionpack/lib/action_view/template_handlers/erb.rb @@ -47,7 +47,7 @@ module ActionView end def cache_fragment(block, name = {}, options = nil) #:nodoc: - @view.fragment_for(block, name, options) { @view.output_buffer } + @view.fragment_for(block, name, options) { @view.response.template.output_buffer ||= '' } end end end -- cgit v1.2.3