Module: Hamlit::StringInterpolation

Defined in:
lib/hamlit/string_interpolation.rb

Class Method Summary collapse

Class Method Details

.compile(code) ⇒ Object

‘code` param must be valid string literal



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hamlit/string_interpolation.rb', line 6

def compile(code)
  [].tap do |exps|
    tokens = Ripper.lex(code.strip)
    tokens.pop while tokens.last && %i[on_comment on_sp].include?(tokens.last[1])

    if tokens.size < 2
      raise Hamlit::InternalError.new("Expected token size >= 2 but got: #{tokens.size}")
    end
    compile_tokens!(exps, tokens)
  end
end