class Slim::Smart::Escaper

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

@api private

Public Instance Methods

call(exp) click to toggle source
Calls superclass method
# File lib/slim/smart/escaper.rb, line 11
def call(exp)
  if options[:smart_text_escaping]
    super
  else
    exp
  end
end
on_slim_text(type, content) click to toggle source
# File lib/slim/smart/escaper.rb, line 19
def on_slim_text(type, content)
  [:escape, type != :verbatim, [:slim, :text, type, compile(content)]]
end
on_static(string) click to toggle source
# File lib/slim/smart/escaper.rb, line 23
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