Class: Liquid::Increment
- Includes:
- ParserSwitching
- Defined in:
- lib/liquid/tags/increment.rb
Instance Attribute Summary collapse
-
#variable_name ⇒ Object
readonly
Returns the value of attribute variable_name.
Attributes inherited from Tag
#line_number, #nodelist, #parse_context, #tag_name
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ Increment
constructor
A new instance of Increment.
- #lax_parse(markup) ⇒ Object
- #render_to_output_buffer(context, output) ⇒ Object
- #strict2_parse(markup) ⇒ Object
- #strict_parse(markup) ⇒ Object
Methods included from ParserSwitching
#parse_with_selected_parser, #strict2_mode?, #strict_parse_with_error_mode_fallback
Methods inherited from Tag
#blank?, disable_tags, #name, parse, #parse, #raw, #render
Constructor Details
#initialize(tag_name, markup, options) ⇒ Increment
Returns a new instance of Increment.
30 31 32 33 |
# File 'lib/liquid/tags/increment.rb', line 30 def initialize(tag_name, markup, ) super parse_with_selected_parser(markup) end |
Instance Attribute Details
#variable_name ⇒ Object (readonly)
Returns the value of attribute variable_name.
28 29 30 |
# File 'lib/liquid/tags/increment.rb', line 28 def variable_name @variable_name end |
Instance Method Details
#lax_parse(markup) ⇒ Object
35 36 37 |
# File 'lib/liquid/tags/increment.rb', line 35 def lax_parse(markup) @variable_name = markup.strip end |
#render_to_output_buffer(context, output) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/liquid/tags/increment.rb', line 49 def render_to_output_buffer(context, output) counter_environment = context.environments.first value = counter_environment[@variable_name] || 0 counter_environment[@variable_name] = value + 1 output << value.to_s output end |
#strict2_parse(markup) ⇒ Object
43 44 45 46 47 |
# File 'lib/liquid/tags/increment.rb', line 43 def strict2_parse(markup) p = @parse_context.new_parser(markup.strip) @variable_name = p.consume(:id) p.consume(:end_of_string) end |
#strict_parse(markup) ⇒ Object
39 40 41 |
# File 'lib/liquid/tags/increment.rb', line 39 def strict_parse(markup) lax_parse(markup) end |