Class: Liquid::Decrement

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

Overview

Hello: decrement variable %

gives you:

Hello: -1
Hello: -2
Hello: -3

Instance Attribute Summary

Attributes inherited from Tag

#line_number, #nodelist, #parse_context, #tag_name

Instance Method Summary collapse

Methods inherited from Tag

#blank?, disable_tags, #name, parse, #parse, #raw, #render

Methods included from ParserSwitching

#parse_with_selected_parser, #strict_parse_with_error_mode_fallback

Constructor Details

#initialize(tag_name, markup, options) ⇒ Decrement

Returns a new instance of Decrement.



23
24
25
26
# File 'lib/liquid/tags/decrement.rb', line 23

def initialize(tag_name, markup, options)
  super
  @variable = markup.strip
end

Instance Method Details

#render_to_output_buffer(context, output) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/liquid/tags/decrement.rb', line 28

def render_to_output_buffer(context, output)
  value = context.environments.first[@variable] ||= 0
  value -= 1
  context.environments.first[@variable] = value
  output << value.to_s
  output
end