Class: EsiForRack::Node::Choose

Inherits:
EsiForRack::Node show all
Defined in:
lib/esi_for_rack/node.rb

Constant Summary

Constants inherited from EsiForRack::Node

IncludeFailedError

Instance Attribute Summary

Attributes inherited from EsiForRack::Node

#context, #node

Instance Method Summary collapse

Methods inherited from EsiForRack::Node

#execute_in_place!, #init

Instance Method Details

#executeObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/esi_for_rack/node.rb', line 70

def execute
  whens = node.css('esi_when').to_a
  raise "choose block contains no when elements" if whens.empty?
  
  otherwise = node.css('esi_otherwise')[0]

  whens.each do |esi_when|
    if EsiAttributeLanguage::Grammar.parse(esi_when['test']).execute(context.resolver).equal?(true)
      context.process(esi_when)
      return esi_when.to_str
    end
  end
  if otherwise
    context.process(otherwise)
    return otherwise.to_str
  end
  nil
end