Class: Luoma::HTMLSafe

Inherits:
Drop
  • Object
show all
Defined in:
lib/luoma/drops/html_safe.rb,
sig/luoma/drops/html_safe.rbs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Drop

#contains?, #each, #eq?, #fetch, #gt?, #key?, #length, #lt?, #slice, #to_a, #to_s

Constructor Details

#initialize(s) ⇒ HTMLSafe

(String) -> void

Parameters:

  • s (String)


16
17
18
19
# File 'lib/luoma/drops/html_safe.rb', line 16

def initialize(s)
  super()
  @s = s
end

Class Method Details

.escape(value) ⇒ HTMLSafe

(String | HTMLSafe) -> HTMLSafe

Parameters:

Returns:



6
7
8
# File 'lib/luoma/drops/html_safe.rb', line 6

def self.escape(value)
  value.is_a?(String) ? HTMLSafe.new(Luoma.escape(value)) : value
end

.from(value) ⇒ HTMLSafe

(String | HTMLSafe) -> HTMLSafe

Parameters:

Returns:



11
12
13
# File 'lib/luoma/drops/html_safe.rb', line 11

def self.from(value)
  value.is_a?(String) ? HTMLSafe.new(value) : value
end

Instance Method Details

#render(context) ⇒ Object

Signature:

  • (RenderContext) -> String?



32
33
34
# File 'lib/luoma/drops/html_safe.rb', line 32

def render(context)
  @s
end

#to_primitive(hint, context) ⇒ Object

Signature:

  • (:data | :numeric | :string | :boolean, RenderContext) -> untyped



22
23
24
25
26
27
28
29
# File 'lib/luoma/drops/html_safe.rb', line 22

def to_primitive(hint, context)
  case hint
  when :string, :data
    @s
  else
    :nothing
  end
end