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



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

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



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

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)



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

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



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

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