Module: ActionView::Helpers::TagHelper
Overview
This is poor man’s Builder for the rare cases where you need to programmatically make tags but can’t use Builder.
Instance Method Summary collapse
-
#cdata_section(content) ⇒ Object
Returns a CDATA section for the given
content. -
#content_tag(name, content, options = nil) ⇒ Object
Examples: *
content_tag("p", "Hello world!") => <p>Hello world!</p>*content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") =><div class="strong"><p>Hello world!</p></div>. -
#tag(name, options = nil, open = false) ⇒ Object
Examples: *
tag("br") => <br />*tag("input", { "type" => "text"}) => <input type="text" />.
Instance Method Details
#cdata_section(content) ⇒ Object
Returns a CDATA section for the given content. CDATA sections are used to escape blocks of text containing characters which would otherwise be recognized as markup. CDATA sections begin with the string <![CDATA[ and end with (and may not contain) the string ]]>.
30 31 32 |
# File 'lib/action_view/helpers/tag_helper.rb', line 30 def cdata_section(content) "<![CDATA[#{content}]]>" end |
#content_tag(name, content, options = nil) ⇒ Object
Examples:
-
content_tag("p", "Hello world!") => <p>Hello world!</p> -
content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") =><div class="strong"><p>Hello world!</p></div>
21 22 23 |
# File 'lib/action_view/helpers/tag_helper.rb', line 21 def content_tag(name, content, = nil) "<#{name}#{(.stringify_keys) if }>#{content}</#{name}>" end |
#tag(name, options = nil, open = false) ⇒ Object
Examples:
-
tag("br") => <br /> -
tag("input", { "type" => "text"}) => <input type="text" />
13 14 15 |
# File 'lib/action_view/helpers/tag_helper.rb', line 13 def tag(name, = nil, open = false) "<#{name}#{(.stringify_keys) if }" + (open ? ">" : " />") end |