๐Ÿ“ฆ EdwonLim / node-less

๐Ÿ“„ attribute.js ยท 30 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30(function(module) {

    var Attribute = function (key, op, value) {
        this.key = key;
        this.op = op;
        this.value = value;
    };

    Attribute.prototype = {
        type: "Attribute",
        accept: function (visitor) {
            this.value = visitor.visit(this.value);
        },
        eval: function (env) {
            return new Attribute(this.key.eval ? this.key.eval(env) : this.key,
                this.op, (this.value && this.value.eval) ? this.value.eval(env) : this.value);
        },
        toCSS: function (env) {
            var value = this.key.toCSS ? this.key.toCSS(env) : this.key;
            if (this.op) {
                value += this.op;
                value += (this.value.toCSS ? this.value.toCSS(env) : this.value);
            }
            return '[' + value + ']';
        }
    };

    module.exports = Attribute;

})(module);