Class: Liquid::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid/expression.rb

Defined Under Namespace

Classes: MethodLiteral

Constant Summary collapse

LITERALS =
{
  nil => nil, 'nil'.freeze => nil, 'null'.freeze => nil, ''.freeze => nil,
  'true'.freeze  => true,
  'false'.freeze => false,
  'blank'.freeze => MethodLiteral.new(:blank?, '').freeze,
  'empty'.freeze => MethodLiteral.new(:empty?, '').freeze
}

Class Method Summary collapse

Class Method Details

.parse(markup) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/liquid/expression.rb', line 24

def self.parse(markup)
  if LITERALS.key?(markup)
    LITERALS[markup]
  else
    case markup
    when /\A'(.*)'\z/m # Single quoted strings
      $1
    when /\A"(.*)"\z/m # Double quoted strings
      $1
    when /\A(-?\d+)\z/ # Integer and floats
      $1.to_i
    when /\A\((\S+)\.\.(\S+)\)\z/ # Ranges
      RangeLookup.parse($1, $2)
    when /\A(-?\d[\d\.]+)\z/ # Floats
      $1.to_f
    else
      VariableLookup.parse(markup)
    end
  end
end