Class: Skim::Interpolation Private

Inherits:
Slim::Filter
  • Object
show all
Defined in:
lib/skim/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

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
# File 'lib/skim/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
      block << [:dynamic, "'\#{'"]
      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