Module: Babl::Operators::Switch::DSL
- Included in:
- Template
- Defined in:
- lib/babl/operators/switch.rb
Instance Method Summary collapse
-
#switch(conds = Utils::Hash::EMPTY) ⇒ Object
Conditional switching between different templates.
Instance Method Details
#switch(conds = Utils::Hash::EMPTY) ⇒ Object
Conditional switching between different templates
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/babl/operators/switch.rb', line 10 def switch(conds = Utils::Hash::EMPTY) conds = conds.map { |cond, value| [unscoped.reset_continue.call(cond), unscoped.call(value)] } construct_node { |node, context| nodes = conds.map { |cond, value| cond_node = cond.builder.precompile( Nodes::InternalValue.instance, context ) value_node = value.builder.precompile( Nodes::TerminalValue.instance, context.merge(continue: node) ) [cond_node, value_node] } Nodes::Switch.new(nodes) }.reset_continue end |