Class: Slim::Interpolation Private

Inherits:
Filter
  • Object
show all
Defined in:
lib/slim/interpolation.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 interpolation of #var_name in the expressions ‘[:slim, :interpolate, string]`.

Instance Method Summary collapse

Methods inherited from Filter

#on_slim_attrs, #on_slim_condcomment, #on_slim_control, #on_slim_embedded, #on_slim_output, #on_slim_tag

Instance Method Details

#on_slim_interpolate(string) ⇒ Array

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.

Handle interpolate expression ‘[:slim, :interpolate, string]`

Parameters:

  • string (String)

    Static interpolate

Returns:

  • (Array)

    Compiled temple expression



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/slim/interpolation.rb', line 11

def on_slim_interpolate(string)
  # Interpolate variables in text (#{variable}).
  # Split the text into multiple dynamic and static parts.
  block = [:multi]
  begin
    case string
    when /\A\\#\{/
      # Escaped interpolation
      # Use [:slim, :output] because this is used by InterpolateTiltEngine
      # to filter out protected strings (Issue #141).
      block << [:slim, :output, false, '\'#{\'', [:multi]]
      string = $'
    when /\A#\{/
      # Interpolation
      string, code = parse_expression($')
      escape = code !~ /\A\{.*\}\Z/
      block << [:slim, :output, escape, escape ? code : code[1..-2], [:multi]]
    when /\A(#|[^#]*)/
      # Static text
      block << [:static, $&]
      string = $'
    end
  end until string.empty?
  block
end