Module: Waves::Helpers::TagHelper
- Included in:
- Erubis::Context, Renderers::Scope
- Defined in:
- lib/helpers/tag_helper.rb
Constant Summary collapse
- ESCAPE_TABLE =
{ '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
Instance Method Summary collapse
-
#escape_once(html) ⇒ Object
Returns the escaped
html
without affecting existing escaped entities. - #h(value) ⇒ Object
-
#tag(name, options = nil, open = false) ⇒ Object
Returns an empty HTML tag of type
name
which by default is XHTML compliant.
Instance Method Details
#escape_once(html) ⇒ Object
Returns the escaped html
without affecting existing escaped entities.
escape_once("1 > 2 & 3")
# => "1 < 2 & 3"
31 32 33 |
# File 'lib/helpers/tag_helper.rb', line 31 def escape_once(html) fix_double_escape(h(html.to_s)) end |
#h(value) ⇒ Object
6 7 8 |
# File 'lib/helpers/tag_helper.rb', line 6 def h(value) value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] } end |
#tag(name, options = nil, open = false) ⇒ Object
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 symbols or strings for the attribute names.
tag("br")
# => <br />
tag("br", nil, true)
# => <br>
tag("input", { :type => 'text', :disabled => true })
# => <input type="text" disabled="disabled" />
23 24 25 |
# File 'lib/helpers/tag_helper.rb', line 23 def tag(name, = nil, open = false) "<#{name}#{() if }" + (open ? ">" : " />") end |