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
}
SINGLE_QUOTED_STRING =
/\A'(.*)'\z/m
DOUBLE_QUOTED_STRING =
/\A"(.*)"\z/m
INTEGERS_REGEX =
/\A(-?\d+)\z/
FLOATS_REGEX =
/\A(-?\d[\d\.]+)\z/
RANGES_REGEX =
/\A\((\S+)\.\.(\S+)\)\z/

Class Method Summary collapse

Class Method Details

.parse(markup) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/liquid/expression.rb', line 30

def self.parse(markup)
  if LITERALS.key?(markup)
    LITERALS[markup]
  else
    case markup
    when SINGLE_QUOTED_STRING, DOUBLE_QUOTED_STRING
      $1
    when INTEGERS_REGEX
      $1.to_i
    when RANGES_REGEX
      RangeLookup.parse($1, $2)
    when FLOATS_REGEX
      $1.to_f
    else
      VariableLookup.parse(markup)
    end
  end
end