Module: Zafu::Process::Conditional
- Defined in:
- lib/zafu/process/conditional.rb
Overview
This module manages conditional rendering (if, else, elsif, case, when).
Instance Method Summary collapse
- #expand_with_node(name, klass) ⇒ Object
- #helper ⇒ Object
-
#node(klass = nil) ⇒ Object
Return the node context for a given class (looks up into the hierarchy) or the current node context if klass is nil.
- #r_else ⇒ Object
- #r_if ⇒ Object
- #var ⇒ Object
Instance Method Details
#expand_with_node(name, klass) ⇒ Object
26 27 28 |
# File 'lib/zafu/process/conditional.rb', line 26 def (name, klass) (:node => @context[:node].move_to(name, klass)) end |
#helper ⇒ Object
15 16 17 |
# File 'lib/zafu/process/conditional.rb', line 15 def helper @context[:helper] end |
#node(klass = nil) ⇒ Object
Return the node context for a given class (looks up into the hierarchy) or the current node context if klass is nil.
21 22 23 24 |
# File 'lib/zafu/process/conditional.rb', line 21 def node(klass = nil) return @context[:node] if !klass @context[:node].get(klass) end |
#r_else ⇒ Object
9 10 11 12 13 |
# File 'lib/zafu/process/conditional.rb', line 9 def r_else return nil unless @context[:in_if] # We use 'elsif' just in case there are more then one 'else' clause out "<% elsif true -%>#{expand_with(:in_if => false)}" # do not propagate end |
#r_if ⇒ Object
5 6 7 |
# File 'lib/zafu/process/conditional.rb', line 5 def r_if "<% if true -%>#{expand_with(:in_if => true)}<% end -%>" end |
#var ⇒ Object
def context_with_node(name, klass)
context = @context.dup
context[:node] = context[:node].move_to(name, klass)
end
35 36 37 38 39 40 41 42 |
# File 'lib/zafu/process/conditional.rb', line 35 def var return @var if @var if node.name =~ /^var(\d+)$/ @var = "var#{$1.to_i + 1}" else @var = "var1" end end |