Class: Liquid::Increment

Inherits:
Tag
  • Object
show all
Defined in:
lib/liquid/tags/increment.rb

Overview

Hello: increment variable %

gives you:

Hello: 0
Hello: 1
Hello: 2

Instance Attribute Summary

Attributes inherited from Tag

#context, #nodelist

Instance Method Summary collapse

Methods inherited from Tag

#name, #parse

Constructor Details

#initialize(tag_name, markup, tokens, context) ⇒ Increment

Returns a new instance of Increment.



19
20
21
22
23
# File 'lib/liquid/tags/increment.rb', line 19

def initialize(tag_name, markup, tokens, context)
  @variable = markup.strip

  super
end

Instance Method Details

#render(context) ⇒ Object



25
26
27
28
29
# File 'lib/liquid/tags/increment.rb', line 25

def render(context)
  value = context.environments.first[@variable] ||= 0
  context.environments.first[@variable] = value + 1
  value.to_s
end