diff options
Diffstat (limited to 'actionpack/lib/action_view/helpers/tag_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/tag_helper.rb | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index 7c6903220a..8d3f6be04c 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -3,7 +3,7 @@ require 'erb' module ActionView module Helpers #:nodoc: - # Use these methods to generate HTML tags programmatically when you can't use + # Provides methods to generate HTML tags programmatically when you can't use # a Builder. By default, they output XHTML compliant tags. module TagHelper include ERB::Util @@ -11,25 +11,40 @@ module ActionView # Returns an empty HTML tag of type +name+ which by default is XHTML # compliant. Setting +open+ to true will create an open tag compatible # with HTML 4.0 and below. Add HTML attributes by passing an attributes - # hash to +options+. For attributes with no value like (disabled and - # readonly), give it a value of true in the +options+ hash. You can use + # hash to +options+. + # + # ==== Options + # The +options+ hash is used with attributes with no value like (<tt>disabled</tt> and + # <tt>readonly</tt>), which you can give a value of true in the +options+ hash. You can use # symbols or strings for the attribute names. # + # ==== Examples # tag("br") - # # => <br /> + # # => <br /> + # # tag("br", nil, true) - # # => <br> + # # => <br> + # # tag("input", { :type => 'text', :disabled => true }) - # # => <input type="text" disabled="disabled" /> + # # => <input type="text" disabled="disabled" /> + # + # tag("img", { :src => "open.png" }) + # # => <img src="open.png" /> def tag(name, options = nil, open = false) "<#{name}#{tag_options(options) if options}" + (open ? ">" : " />") end # Returns an HTML block tag of type +name+ surrounding the +content+. Add - # HTML attributes by passing an attributes hash to +options+. For attributes - # with no value like (disabled and readonly), give it a value of true in - # the +options+ hash. You can use symbols or strings for the attribute names. + # HTML attributes by passing an attributes hash to +options+. + # Instead of passing the content as an argument, you can also use a block + # in which case, you pass your +options+ as the second parameter. # + # ==== Options + # The +options+ hash is used with attributes with no value like (<tt>disabled</tt> and + # <tt>readonly</tt>), which you can give a value of true in the +options+ hash. You can use + # symbols or strings for the attribute names. + # + # ==== Examples # content_tag(:p, "Hello world!") # # => <p>Hello world!</p> # content_tag(:div, content_tag(:p, "Hello world!"), :class => "strong") @@ -37,9 +52,6 @@ module ActionView # content_tag("select", options, :multiple => true) # # => <select multiple="multiple">...options...</select> # - # Instead of passing the content as an argument, you can also use a block - # in which case, you pass your +options+ as the second parameter. - # # <% content_tag :div, :class => "strong" do -%> # Hello world! # <% end -%> @@ -61,16 +73,24 @@ module ActionView # otherwise be recognized as markup. CDATA sections begin with the string # <tt><![CDATA[</tt> and end with (and may not contain) the string <tt>]]></tt>. # + # ==== Examples # cdata_section("<hello world>") - # # => <![CDATA[<hello world>]]> + # # => <![CDATA[<hello world>]]> + # + # cdata_section(File.read("hello_world.txt")) + # # => <![CDATA[<hello from a text file]]> def cdata_section(content) "<![CDATA[#{content}]]>" end - # Returns the escaped +html+ without affecting existing escaped entities. + # Returns an escaped version of +html+ without affecting existing escaped entities. # + # ==== Examples # escape_once("1 > 2 & 3") - # # => "1 < 2 & 3" + # # => "1 < 2 & 3" + # + # escape_once("<< Accept & Checkout") + # # => "<< Accept & Checkout" def escape_once(html) fix_double_escape(html_escape(html.to_s)) end |