From f2a021dc06d934f569977a05fa4e579e3f593d34 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 21 Jun 2005 06:43:14 +0000 Subject: Added option to pass in parameters to CaptureHelper#capture, so you can create more advanced view helper methods #1466 [duane.johnson@gmail.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1459 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/capture_helper.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_view/helpers/capture_helper.rb') diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index aba4a85355..1877730c7e 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -48,11 +48,11 @@ module ActionView # <% @greeting = capture do %> # Welcome To my shiny new web page! # <% end %> - def capture(&block) + def capture(*args, &block) # execute the block buffer = eval("_erbout", block.binding) pos = buffer.length - block.call + block.call(*args) # extract the block data = buffer[pos..-1] @@ -77,7 +77,10 @@ module ActionView # alert('hello world') # <% end %> # - # You can use @content_for_header anywhere in your templates + # You can use @content_for_header anywhere in your templates. + # + # NOTE: Beware that content_for is ignored in caches. So you shouldn't use it + # for elements that are going to be fragment cached. def content_for(name, &block) base = controller.instance_variable_get(instance_var_name(name)) || "" data = capture(&block) @@ -85,8 +88,7 @@ module ActionView data end - private - + private def instance_var_name(name) #:nodoc# "@content_for_#{name}" end -- cgit v1.2.3