Sha256: 1a8ac8f44002c655a588081f5ffb2b1fb2511b294856d617499f21ca7235d58a

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true
module Slim
  # Perform interpolation of #{var_name} in the
  # expressions `[:slim, :interpolate, string]`.
  #
  # @api private
  class Interpolation < Filter
    # Handle interpolate expression `[:slim, :interpolate, string]`
    #
    # @param [String] string Static interpolate
    # @return [Array] Compiled temple expression
    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
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
brakeman-6.2.2 bundle/ruby/3.1.0/gems/slim-5.2.1/lib/slim/interpolation.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/slim-5.2.1/lib/slim/interpolation.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/slim-5.2.1/lib/slim/interpolation.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/slim-5.2.1/lib/slim/interpolation.rb
slim-5.2.1 lib/slim/interpolation.rb
slim-5.2.0 lib/slim/interpolation.rb
slim-5.1.1 lib/slim/interpolation.rb