all files / liquidjs/tags/ decrement.js

100% Statements 12/12
100% Branches 2/2
100% Functions 3/3
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21     111×                
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);
        }
    });
 
};