Sha256: 390ba62f877320faa8dadb342bb5fc9be110f6e5779664dea510208405f5f9dc

Contents?: true

Size: 1.07 KB

Versions: 104

Compression:

Stored size: 1.07 KB

Contents

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

104 entries across 90 versions & 6 rubygems

Version Path
brakeman-3.7.2 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.7.0 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.6.2 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
slim-3.0.8 lib/slim/interpolation.rb
brakeman-3.6.1 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.6.0 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.5.0 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.4.1 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.4.0 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.3.5 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.3.4 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.3.3 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.3.2 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
brakeman-3.3.1 bundle/ruby/2.3.0/gems/slim-3.0.7/lib/slim/interpolation.rb
slim-3.0.7 lib/slim/interpolation.rb
brakeman-3.3.0 bundle/ruby/2.3.0/gems/slim-3.0.6/lib/slim/interpolation.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/slim-3.0.6/lib/slim/interpolation.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/slim-3.0.6/lib/slim/interpolation.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/slim-3.0.6/lib/slim/interpolation.rb