Class: Haml::Escapable

Inherits:
Temple::Filter
  • Object
show all
Defined in:
lib/haml/escapable.rb

Overview

Like Temple::Filters::Escapable, but with support for escaping by Haml::Herlpers.html_escape and Haml::Herlpers.escape_once.

Instance Method Summary collapse

Constructor Details

#initializeEscapable

Returns a new instance of Escapable

7
8
9
10
11
12
13
14
# File 'lib/haml/escapable.rb', line 7

def initialize(*)
  super
  @escape_code = "::Haml::Helpers.html_escape((%s))"
  @escaper = eval("proc {|v| #{@escape_code % 'v'} }")
  @once_escape_code = "::Haml::Helpers.escape_once((%s))"
  @once_escaper = eval("proc {|v| #{@once_escape_code % 'v'} }")
  @escape = false
end

Instance Method Details

#on_dynamic(value)

The same as Haml::AttributeBuilder.build_attributes

38
39
40
41
42
43
44
45
46
47
48
# File 'lib/haml/escapable.rb', line 38

def on_dynamic(value)
  [:dynamic,
   if @escape == :once
     @once_escape_code % value
   elsif @escape
     @escape_code % value
   else
     "(#{value}).to_s"
   end
  ]
end

#on_escape(flag, exp)

16
17
18
19
20
21
22
# File 'lib/haml/escapable.rb', line 16

def on_escape(flag, exp)
  old = @escape
  @escape = flag
  compile(exp)
ensure
  @escape = old
end

#on_static(value)

The same as Haml::AttributeBuilder.build_attributes

25
26
27
28
29
30
31
32
33
34
35
# File 'lib/haml/escapable.rb', line 25

def on_static(value)
  [:static,
   if @escape == :once
     @once_escaper[value]
   elsif @escape
     @escaper[value]
   else
     value
   end
  ]
end