Class: XRB::MarkupString

Inherits:
String
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(string = nil, escape = true) ⇒ MarkupString

Returns a new instance of MarkupString.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/xrb/markup.rb', line 47

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.



60
61
62
# File 'lib/xrb/markup.rb', line 60

def self.raw(string)
  self.new(string, false)
end

Instance Method Details

#append_markup(output) ⇒ Object

Append this already-safe markup string to an output buffer.



73
74
75
# File 'lib/xrb/markup.rb', line 73

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.

Returns:



66
67
68
# File 'lib/xrb/markup.rb', line 66

def html_safe?
  true
end