Sha256: db6f1929b0e73114759db3c12542a708f01e220b043684a5f5833c84f9851d78

Contents?: true

Size: 835 Bytes

Versions: 5

Compression:

Stored size: 835 Bytes

Contents

module Slim
  # Perform interpolation of #{var_name}
  # @api private
  class Interpolation < Filter
    # Handle text expression `[:slim, :text, string]`
    #
    # @param [String] string Static text
    # @return [Array] Compiled temple expression
    def on_slim_text(string)
      # Interpolate variables in text (#{variable}).
      # Split the text into multiple dynamic and static parts.
      block = [:multi]
      until string.empty?
        case string
        when /^\\(\#\{[^\}]*\})/
          # Escaped interpolation
          block << [:static, $1]
        when /^\#\{([^\}]*)\}/
          # Interpolation
          block << [:slim, :output, true, $1, [:multi]]
        when /^([^\#]+|\#)/
          # Static text
          block << [:static, $&]
        end
        string = $'
      end
      block
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slim-0.8.1 lib/slim/interpolation.rb
slim-0.8.0 lib/slim/interpolation.rb
slim-0.7.4 lib/slim/interpolation.rb
slim-0.7.3 lib/slim/interpolation.rb
slim-0.7.2 lib/slim/interpolation.rb