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.

Parameters:

  • string (String) (defaults to: nil)

    the string value itself.

  • escape (Boolean) (defaults to: true)

    whether or not to escape the string.



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.

Returns:

  • (Boolean)


53
54
55
# File 'lib/xrb/markup.rb', line 53

def html_safe?
	true
end