aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-04-16 11:34:07 +0200
committerJosé Valim <jose.valim@gmail.com>2011-04-16 11:34:07 +0200
commitab105e6072d291d7024e4e645defa5eff31f6f21 (patch)
treeceb36f53f3f7ac692f0fa075e72ab683566220f1 /actionpack/lib/action_view
parent3e0aedba909562411b8f369115828a79a7a77a0a (diff)
downloadrails-ab105e6072d291d7024e4e645defa5eff31f6f21.tar.gz
rails-ab105e6072d291d7024e4e645defa5eff31f6f21.tar.bz2
rails-ab105e6072d291d7024e4e645defa5eff31f6f21.zip
content_for should work with provide.
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/flows.rb9
-rw-r--r--actionpack/lib/action_view/helpers/capture_helper.rb8
2 files changed, 13 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/flows.rb b/actionpack/lib/action_view/flows.rb
index b5e2c5d37d..995a0b51e4 100644
--- a/actionpack/lib/action_view/flows.rb
+++ b/actionpack/lib/action_view/flows.rb
@@ -19,6 +19,10 @@ module ActionView
def append(key, value)
@content[key] << value
end
+
+ def append!(key, value)
+ @content[key] << value
+ end
end
class StreamingFlow < OutputFlow
@@ -58,6 +62,11 @@ module ActionView
# by provides and resumes back to the fiber if it is
# the key it is waiting for.
def set(key, value)
+ @content[key] = (ActiveSupport::SafeBuffer.new << value)
+ end
+
+ # Append but also resume the fiber if it provided the right key.
+ def append!(key, value)
super
@fiber.resume if @waiting_for == key
end
diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb
index 148d814ac7..0139714240 100644
--- a/actionpack/lib/action_view/helpers/capture_helper.rb
+++ b/actionpack/lib/action_view/helpers/capture_helper.rb
@@ -142,12 +142,12 @@ module ActionView
# The same as +content_for+ but when used with streaming flushes
# straight back to the layout. In other words, if you want to
# concatenate several times to the same buffer when rendering a given
- # template, you should use +content_for+, if not, use +provide+ as it
- # has better streaming support.
+ # template, you should use +content_for+, if not, use +provide+ to tell
+ # the layout to stop looking for more contents.
def provide(name, content = nil, &block)
content = capture(&block) if block_given?
- @_view_flow.set(name, content) if content
- content
+ result = @_view_flow.append!(name, content) if content
+ result unless content
end
# content_for? simply checks whether any content has been captured yet using content_for