1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1× 1× 1× 1× 111× 5× 5× 4× 4× 4× 4× | const Liquid = require('..'); const lexical = Liquid.lexical; const assert = require('../src/util/assert.js'); module.exports = function(liquid) { liquid.registerTag('decrement', { parse: function(token) { var match = token.args.match(lexical.identifier); assert(match, `illegal identifier ${token.args}`); this.variable = match[0]; }, render: function(scope, hash) { var v = scope.get(this.variable); if (typeof v !== 'number') v = 0; scope.set(this.variable, v - 1); } }); }; |