Sha256: 5f90e5885a1ebf5fb80f6ab3f5a430939bb115d6e0d9a04c5e4101665c08d2d6
Contents?: true
Size: 810 Bytes
Versions: 23
Compression:
Stored size: 810 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, options) super @variable = markup.strip end def render(context) value = context.environments.first[@variable] ||= 0 context.environments.first[@variable] = value + 1 value.to_s end end Template.register_tag('increment'.freeze, Increment) end
Version data entries
23 entries across 23 versions & 4 rubygems