all files / liquidjs/tags/ assign.js

100% Statements 13/13
100% Branches 0/0
100% Functions 3/3
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23     111×   27× 27× 26× 26×     26× 26×          
const Liquid = require('..');
const lexical = Liquid.lexical;
const Promise = require('any-promise');
const re = new RegExp(`(${lexical.identifier.source})\\s*=(.*)`);
const assert = require('../src/util/assert.js');
 
module.exports = function(liquid) {
 
    liquid.registerTag('assign', {
        parse: function(token){
            var match = token.args.match(re);
            assert(match, `illegal token ${token.raw}`);
            this.key = match[1];
            this.value = match[2];
        },
        render: function(scope) {
            scope.set(this.key, liquid.evalOutput(this.value, scope));
            return Promise.resolve('');
        }
    });
 
};