class Sliq::Interpolation

Public Instance Methods

on_slim_attrvalue(escape, code) click to toggle source
# File lib/sliq.rb, line 47
def on_slim_attrvalue(escape, code)
  if code =~ /\A\{\{.*\}\}\Z/
    [:static, code]
  else
    [:slim, :attrvalue, escape, code]
  end
end
on_slim_interpolate(string) click to toggle source
# File lib/sliq.rb, line 55
def on_slim_interpolate(string)
  block = [:multi]
  begin
    case string
    when /\A\\{\{/
      # Escaped interpolation
      block << [:static, '{{']
      string = $'
    when /\A\{{2}((?>[^{}]|(\{{2}(?>[^{}]|\g<1>)*\}{2}))*)\}{2}/
      # Interpolation
      string, code = $', $1
      escape = code !~ /\A\{.*\}\Z/
      block << [:slim, :output, escape, escape ? code : code[1..-2], [:multi]]
    # TODO: make reg exp for liquid static text
    when /\A([#\\]?[^#\\]*([#\\][^\\#\{][^#\\]*)*)/
      # Static text
      block << [:static, $&]
      string = $'
    end
  end until string.empty?
  block
end