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

Instance Method Details

#expand_with_node(name, klass) ⇒ Object



26
27
28
# File 'lib/zafu/process/conditional.rb', line 26

def expand_with_node(name, klass)
  expand_with(:node => @context[:node].move_to(name, klass))
end

#helperObject



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_elseObject



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_ifObject



5
6
7
# File 'lib/zafu/process/conditional.rb', line 5

def r_if
  "<% if true -%>#{expand_with(:in_if => true)}<% end -%>"
end

#varObject

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