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_control, #on_slim_embedded, #on_slim_output, #on_slim_text

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



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

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
      block << [:static, '#{']
      string = $'
    when /\A#\{((?>[^{}]|(\{(?>[^{}]|\g<1>)*\}))*)\}/
      # Interpolation
      string, code = $', $1
      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