Class: Liquid::Increment
Overview
Hello: increment variable %
gives you:
Hello: 0
Hello: 1
Hello: 2
Instance Attribute Summary
Attributes inherited from Tag
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens, context) ⇒ Increment
constructor
A new instance of Increment.
- #render(context) ⇒ Object
Methods inherited from Tag
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 |