Class: HtmlSafeString
Overview
Simple class that extends strings to do html escapes on incoming concats, only defined if not running under Rails
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<<(value) ⇒ Object
-
#concat(value) ⇒ Object
The magic - escape values that are concatenated onto this string before concatenation.
- #html_safe ⇒ Object
- #html_safe? ⇒ Boolean
-
#initialize(*args) ⇒ HtmlSafeString
constructor
A new instance of HtmlSafeString.
Constructor Details
#initialize(*args) ⇒ HtmlSafeString
Returns a new instance of HtmlSafeString.
27 28 29 30 |
# File 'lib/iron/web/string.rb', line 27 def initialize(*args) @html_safe = true super end |
Instance Method Details
#+(other) ⇒ Object
50 51 52 |
# File 'lib/iron/web/string.rb', line 50 def +(other) dup.concat(other) end |
#<<(value) ⇒ Object
54 55 56 |
# File 'lib/iron/web/string.rb', line 54 def <<(value) concat(value) end |
#concat(value) ⇒ Object
The magic - escape values that are concatenated onto this string before concatenation.
42 43 44 45 46 47 48 |
# File 'lib/iron/web/string.rb', line 42 def concat(value) if !html_safe? || value.html_safe? super(value) else super(Html.escape_once(value)) end end |
#html_safe ⇒ Object
36 37 38 |
# File 'lib/iron/web/string.rb', line 36 def html_safe self end |
#html_safe? ⇒ Boolean
32 33 34 |
# File 'lib/iron/web/string.rb', line 32 def html_safe? @html_safe end |