Class: Slim::Smart::Escaper Private

Inherits:
Filter
  • Object
show all
Defined in:
lib/slim/smart/escaper.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Perform smart entity escaping in the expressions [:slim, :text, type, Expression].

Instance Method Summary collapse

Methods inherited from Filter

#on_slim_control, #on_slim_embedded, #on_slim_output

Instance Method Details

#call(exp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


10
11
12
13
14
15
16
# File 'lib/slim/smart/escaper.rb', line 10

def call(exp)
  if options[:smart_text_escaping]
    super
  else
    exp
  end
end

#on_slim_text(type, content) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'lib/slim/smart/escaper.rb', line 18

def on_slim_text(type, content)
  [:escape, type != :verbatim, [:slim, :text, type, compile(content)]]
end

#on_static(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/slim/smart/escaper.rb', line 22

def on_static(string)
  # Prevent obvious &foo; and Ӓ and ÿ entities from escaping.
  block = [:multi]
  until string.empty?
    case string
    when /\A&([a-z][a-z0-9]*|#x[0-9a-f]+|#\d+);/i
      # Entity.
      block << [:escape, false, [:static, $&]]
      string = $'
    when /\A&?[^&]*/
      # Other text.
      block << [:static, $&]
      string = $'
    end
  end
  block
end