55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
|
|
|
|
tree.Rule = function Rule(name, value, index) {
|
|
this.name = name;
|
|
this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]);
|
|
this.index = index;
|
|
|
|
if (name.charAt(0) === '@') {
|
|
this.variable = true;
|
|
} else { this.variable = false }
|
|
};
|
|
tree.Rule.prototype.toCSS = function () {
|
|
if (this.variable) { return "" }
|
|
else {
|
|
return this.name + ": " + this.value.toCSS() + ";";
|
|
}
|
|
};
|
|
|
|
tree.Rule.prototype.eval = function (context) {
|
|
return new(tree.Rule)(this.name, this.value.eval(context));
|
|
};
|
|
|
|
tree.Value = function Value(value) {
|
|
this.value = value;
|
|
this.is = 'value';
|
|
};
|
|
tree.Value.prototype = {
|
|
eval: function (env) {
|
|
if (this.value.length === 1) {
|
|
return this.value[0].eval(env);
|
|
} else {
|
|
return new(tree.Value)(this.value.map(function (v) {
|
|
return v.eval(env);
|
|
}));
|
|
}
|
|
},
|
|
toCSS: function () {
|
|
return this.value.map(function (e) {
|
|
return e.toCSS();
|
|
}).join(', ');
|
|
}
|
|
};
|
|
|
|
tree.Shorthand = function Shorthand(a, b) {
|
|
this.a = a;
|
|
this.b = b;
|
|
};
|
|
|
|
tree.Shorthand.prototype = {
|
|
toCSS: function (env) {
|
|
return this.a.toCSS(env) + "/" + this.b.toCSS(env);
|
|
},
|
|
eval: function () { return this }
|
|
};
|