diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-21 06:43:14 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-21 06:43:14 +0000 |
commit | f2a021dc06d934f569977a05fa4e579e3f593d34 (patch) | |
tree | aaa4c157d7507f88ff315267997b66d6695ea526 /actionpack/lib/action_view/helpers | |
parent | 0bdd44accae978a04f51b1adace09db3a6f77f33 (diff) | |
download | rails-f2a021dc06d934f569977a05fa4e579e3f593d34.tar.gz rails-f2a021dc06d934f569977a05fa4e579e3f593d34.tar.bz2 rails-f2a021dc06d934f569977a05fa4e579e3f593d34.zip |
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
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/capture_helper.rb | 12 |
1 files changed, 7 insertions, 5 deletions
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 |