From dfc15e122afcc7e3cfabaadfbac639af7e846b5a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 28 Jun 2007 18:32:34 +0000 Subject: Improve capture helper documentation. Closes #8796. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7148 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 + .../lib/action_view/helpers/capture_helper.rb | 66 ++++++++++++++-------- 2 files changed, 43 insertions(+), 25 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 6fb3acc1f2..c5953703a7 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Improve capture helper documentation. #8796 [kampers] + * Prefix nested resource named routes with their action name, e.g. new_group_user_path(@group) instead of group_new_user_path(@group). The old nested action named route is deprecated in Rails 1.2.4. #8558 [David Chelimsky] * Allow sweepers to be created solely for expiring after controller actions, not model changes [DHH] diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 7cf2b02659..14bc8efee2 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -3,10 +3,10 @@ module ActionView # CaptureHelper exposes methods to let you extract generated markup which # can be used in other parts of a template or layout file. # It provides a method to capture blocks into variables through capture and - # a way to capture a block of code for use in a layout through content_for. + # a way to capture a block of markup for use in a layout through content_for. module CaptureHelper - # The capture method allows you to extract a part of the template into a - # variable. You can then use this value anywhere in your templates or layout. + # The capture method allows you to extract part of a template into a + # variable. You can then use this variable anywhere in your templates or layout. # # ==== Examples # The capture method can be used in RHTML (ERb) templates... @@ -22,8 +22,7 @@ module ActionView # "The current timestamp is #{Time.now}." # end # - # You can then use the content as a variable anywhere else. For - # example: + # You can then use that variable anywhere else. For example: # # # <%= @greeting %> @@ -46,21 +45,21 @@ module ActionView end end - # Calling content_for stores the block of markup in an identifier for later use. - # You can make subsequent calls to the stored content in another template or in the layout - # by calling it by name with yield. + # Calling content_for stores a block of markup in an identifier for later use. + # You can make subsequent calls to the stored content in other templates or the layout + # by passing the identifier as an argument to yield. # # ==== Examples # - # <% content_for("authorized") do %> - # alert('You are not authorized for that!') + # <% content_for :not_authorized do %> + # alert('You are not authorized to do that!') # <% end %> # - # You can then use yield :authorized anywhere in your templates. + # You can then use yield :not_authorized anywhere in your templates. # - # <%= yield :authorized if current_user == nil %> + # <%= yield :not_authorized if current_user.nil? %> # - # You can also use these variables in a layout. For example: + # You can also use this syntax alongside an existing call to yield in a layout. For example: # # # @@ -73,33 +72,50 @@ module ActionView # # # - # And now we'll create a view that has a content_for call that + # And now, we'll create a view that has a content_for call that # creates the script identifier. # # # Please login! # - # <% content_for("script") do %> - # + # <% content_for :script do %> + # # <% end %> # - # Then in another view you may want to do something like this: + # Then, in another view, you could to do something like this: # # <%= link_to_remote 'Logout', :action => 'logout' %> # - # <% content_for("script") do %> + # <% content_for :script do %> # <%= javascript_include_tag :defaults %> # <% end %> # - # That will include Prototype and Scriptaculous into the page; this technique - # is useful if you'll only be using these scripts on a few views. + # That will place