Method: Zafu::Process::Conditional#r_elsif

Defined in:
lib/zafu/process/conditional.rb

#r_elsif(cond = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/zafu/process/conditional.rb', line 23

def r_elsif(cond = nil)
  return '' unless @context[:in_if]
  cond ||= get_condition
  return unless cond

  res = expand_with(:in_if => false, :markup => nil)

  # We use 'elsif' just in case there are more then one 'else' clause
  if markup = @context[:markup]
    if @markup.tag.blank?
      # Copy markup tag
      @markup.tag = markup.tag
      @markup.steal_html_params_from(@params)
      markup.params.each do |k, v|
        next if @markup.params[k]
        @markup.set_param(k, v)
      end

      markup.dyn_params.each do |k, v|
        next if @markup.params[k] || @markup.dyn_params[k]
        @markup.set_dyn_param(k, v)
      end
      inner = wrap(res)
    else
      markup.done = false
      # Wrap with both markup (ours and the else/elsif clause).
      inner = markup.wrap(wrap(res))
    end
    out "<% elsif #{cond} %>#{inner}" # do not propagate
  else
    #@markup.done = true # never wrap else/elsif clause
    out "<% elsif #{cond} %>#{res}" # do not propagate
  end
end