Class: XRB::MarkupString
- Inherits:
-
String
- Object
- String
- XRB::MarkupString
- Defined in:
- lib/xrb/markup.rb,
ext/xrb/xrb.c
Overview
Initialized from text which is escaped to use HTML entities.
Class Method Summary collapse
-
.raw(string) ⇒ Object
Generate a valid MarkupString withot any escaping.
Instance Method Summary collapse
- #append_markup(output) ⇒ Object
-
#html_safe? ⇒ Boolean
This “string” is already escaped, thus it is safe to append to the output buffer.
-
#initialize(string = nil, escape = true) ⇒ MarkupString
constructor
A new instance of MarkupString.
Constructor Details
#initialize(string = nil, escape = true) ⇒ MarkupString
Returns a new instance of MarkupString.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xrb/markup.rb', line 34 def initialize(string = nil, escape = true) if string if escape string = ::CGI.escape_html(string) end super(string) else super() end end |
Class Method Details
.raw(string) ⇒ Object
Generate a valid MarkupString withot any escaping.
47 48 49 |
# File 'lib/xrb/markup.rb', line 47 def self.raw(string) self.new(string, false) end |
Instance Method Details
#append_markup(output) ⇒ Object
57 58 59 |
# File 'lib/xrb/markup.rb', line 57 def append_markup(output) output << self end |
#html_safe? ⇒ Boolean
This “string” is already escaped, thus it is safe to append to the output buffer. This predicate is used by Rails’ ActionView::OutputBuffer to determine if the string should be escaped or not.
53 54 55 |
# File 'lib/xrb/markup.rb', line 53 def html_safe? true end |