Sha256: 109ab44e6884f3d7eb6629ac11036c7a0d3a3b9c3081d1d46be0b4ece5c7a40a
Contents?: true
Size: 814 Bytes
Versions: 6
Compression:
Stored size: 814 Bytes
Contents
module Liquid # increment is used in a place where one needs to insert a counter # into a template, and needs the counter to survive across # multiple instantiations of the template. # (To achieve the survival, the application must keep the context) # # if the variable does not exist, it is created with value 0. # Hello: {% increment variable %} # # gives you: # # Hello: 0 # Hello: 1 # Hello: 2 # class Increment < Tag def initialize(tag_name, markup, tokens) @variable = markup.strip super end def render(context) value = context.environments.first[@variable] ||= 0 context.environments.first[@variable] = value + 1 value.to_s end private end Template.register_tag('increment', Increment) end
Version data entries
6 entries across 6 versions & 2 rubygems