0
- # Container for liquid nodes which conveniently wrap
ps decision making logic
0
+ # Container for liquid nodes which conveniently wrap
s decision making logic
0
# c = Condition.new('1', '==', '1')
0
+ class Condition
#:nodoc:0
'==' => lambda { |cond, left, right| cond.send(:equal_variables, left, right) },
0
'!=' => lambda { |cond, left, right| !cond.send(:equal_variables, left, right) },
0
@@ -14,7 +14,8 @@ module Liquid
0
+ 'contains' => lambda { |cond, left, right| left.include?(right) },
0
@@ -26,10 +27,29 @@ module Liquid
0
def initialize(left = nil, operator = nil, right = nil)
0
@left, @operator, @right = left, operator, right
0
+ @child_condition = nil
0
def evaluate(context = Context.new)
0
- interpret_condition(left, right, operator, context)
0
+ result = interpret_condition(left, right, operator, context)
0
+ result || @child_condition.evaluate(context)
0
+ result && @child_condition.evaluate(context)
0
+ @child_relation, @child_condition = :or, condition
0
+ @child_relation, @child_condition = :and, condition
0
@@ -38,6 +58,10 @@ module Liquid
0
+ "#<Condition #{[@left, @operator, @right].compact.join(' ')}>"
0
@@ -70,18 +94,20 @@ module Liquid
0
return context[left] if op == nil
0
left, right = context[left], context[right]
0
operation = self.class.operators[op] || raise(ArgumentError.new("Error in tag '#{name}' - Unknown operator #{op}"))
0
if operation.respond_to?(:call)
0
operation.call(self, left, right)
0
- elsif left.respond_to?(operation) and right.respond_to?(operation)
0
+ elsif left.respond_to?(operation) and right.respond_to?(operation)
0
left.send(operation, right)
0
class ElseCondition < Condition