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
This commit is contained in:
David Heinemeier Hansson
2005-06-21 06:43:14 +00:00
parent 0bdd44acca
commit f2a021dc06
3 changed files with 18 additions and 9 deletions

View File

@@ -1,5 +1,12 @@
*SVN*
* Added option to pass in parameters to CaptureHelper#capture, so you can create more advanced view helper methods #1466 [duane.johnson@gmail.com]. Example:
<% show_calendar(:year => 2005, :month => 6) do |day, options| %>
<% options[:bgcolor] = '#dfd' if 10..15.include? day %>
[<%= day %>]
<% end %>
* Changed the default name of the input tag generated by FormTagHelper#submit_tag from "submit" to "commit" so it doesn't clash with form.submit() calls in Javascript #1271
* Fixed relative urls support for lighttpd #1048 [Nicholas Seckar/maznawak@nerim.net]

View File

@@ -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

File diff suppressed because one or more lines are too long