Class: RSX::SafeString

Inherits:
String
  • Object
show all
Defined in:
lib/rsx/safe_string.rb

Overview

An HTML-safe string. Anything wrapped in a SafeString is emitted verbatim; everything else that flows into a template is escaped.

SafeString subclasses String so it interoperates with ActionView output buffers, ActiveSupport::SafeBuffer and plain Ruby string operations without requiring ActiveSupport to be loaded.

Instance Method Summary collapse

Instance Method Details

#*(times) ⇒ Object



34
35
36
# File 'lib/rsx/safe_string.rb', line 34

def *(times)
  SafeString.new(super)
end

#+(other) ⇒ Object

Concatenation keeps the safety contract: unsafe operands are escaped.



25
26
27
# File 'lib/rsx/safe_string.rb', line 25

def +(other)
  SafeString.new(super(RSX.child(other)))
end

#<<(other) ⇒ Object Also known as: concat



29
30
31
# File 'lib/rsx/safe_string.rb', line 29

def <<(other)
  super(RSX.child(other))
end

#html_safe?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/rsx/safe_string.rb', line 11

def html_safe?
  true
end

#inspectObject



38
39
40
# File 'lib/rsx/safe_string.rb', line 38

def inspect
  "#<RSX::SafeString #{super}>"
end

#to_sObject

Rails calls this when concatenating into an output buffer.



16
17
18
# File 'lib/rsx/safe_string.rb', line 16

def to_s
  self
end

#to_safe_stringObject



20
21
22
# File 'lib/rsx/safe_string.rb', line 20

def to_safe_string
  self
end