Class: Liquid::Decrement
Overview
Hello: decrement variable %
gives you:
Hello: -1
Hello: -2
Hello: -3
Instance Attribute Summary
Attributes inherited from Tag
#line_number, #nodelist, #options, #warnings
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ Decrement
constructor
A new instance of Decrement.
- #render(context) ⇒ Object
Methods inherited from Tag
#blank?, #name, #parse, parse, #raw
Methods included from ParserSwitching
Constructor Details
#initialize(tag_name, markup, options) ⇒ Decrement
Returns a new instance of Decrement.
22 23 24 25 |
# File 'lib/liquid/tags/decrement.rb', line 22 def initialize(tag_name, markup, ) super @variable = markup.strip end |
Instance Method Details
#render(context) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/liquid/tags/decrement.rb', line 27 def render(context) value = context.environments.first[@variable] ||= 0 value = value - 1 context.environments.first[@variable] = value value.to_s end |