Method: Liquid::Cycle#render_to_output_buffer

Defined in:
lib/liquid/tags/cycle.rb

#render_to_output_buffer(context, output) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/liquid/tags/cycle.rb', line 43

def render_to_output_buffer(context, output)
  context.registers[:cycle] ||= {}

  key       = context.evaluate(@name)
  iteration = context.registers[:cycle][key].to_i

  val = context.evaluate(@variables[iteration])

  if val.is_a?(Array)
    val = val.join
  elsif !val.is_a?(String)
    val = val.to_s
  end

  output << val

  iteration += 1
  iteration = 0 if iteration >= @variables.size

  context.registers[:cycle][key] = iteration
  output
end