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


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

def execute
  whens = node.css('esi_when').to_a
  raise "no when's within choose" 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.inner_html
    end
  end
  if otherwise
    context.process(otherwise)
    return otherwise.inner_html
  end
  nil
end