2010-03-13 16:34:48 +08:00
|
|
|
if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
|
2010-02-24 02:39:05 +08:00
|
|
|
|
2010-06-08 03:47:41 +08:00
|
|
|
tree.Rule = function Rule(name, value, index) {
|
2010-02-24 02:39:05 +08:00
|
|
|
this.name = name;
|
2010-03-08 07:50:31 +08:00
|
|
|
this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]);
|
2010-06-08 03:47:41 +08:00
|
|
|
this.index = index;
|
2010-02-24 02:39:05 +08:00
|
|
|
|
|
|
|
if (name.charAt(0) === '@') {
|
|
|
|
this.variable = true;
|
|
|
|
} else { this.variable = false }
|
|
|
|
};
|
2010-06-12 09:45:51 +08:00
|
|
|
tree.Rule.prototype.toCSS = function (env) {
|
2010-02-26 06:56:21 +08:00
|
|
|
if (this.variable) { return "" }
|
|
|
|
else {
|
2010-06-12 09:45:51 +08:00
|
|
|
return this.name + (env.compress ? ':' : ': ') + this.value.toCSS(env) + ";";
|
2010-02-26 06:56:21 +08:00
|
|
|
}
|
2010-02-24 02:39:05 +08:00
|
|
|
};
|
|
|
|
|
2010-04-23 01:07:41 +08:00
|
|
|
tree.Rule.prototype.eval = function (context) {
|
|
|
|
return new(tree.Rule)(this.name, this.value.eval(context));
|
|
|
|
};
|
|
|
|
|
2010-03-02 04:32:21 +08:00
|
|
|
tree.Value = function Value(value) {
|
2010-02-24 02:39:05 +08:00
|
|
|
this.value = value;
|
|
|
|
this.is = 'value';
|
|
|
|
};
|
2010-03-08 12:38:10 +08:00
|
|
|
tree.Value.prototype = {
|
|
|
|
eval: function (env) {
|
|
|
|
if (this.value.length === 1) {
|
2010-05-08 11:21:16 +08:00
|
|
|
return this.value[0].eval(env);
|
2010-03-08 12:38:10 +08:00
|
|
|
} else {
|
2010-05-07 00:46:36 +08:00
|
|
|
return new(tree.Value)(this.value.map(function (v) {
|
|
|
|
return v.eval(env);
|
|
|
|
}));
|
2010-03-08 12:38:10 +08:00
|
|
|
}
|
|
|
|
},
|
2010-06-12 09:45:51 +08:00
|
|
|
toCSS: function (env) {
|
2010-03-08 12:38:10 +08:00
|
|
|
return this.value.map(function (e) {
|
2010-06-12 09:45:51 +08:00
|
|
|
return e.toCSS(env);
|
|
|
|
}).join(env.compress ? ',' : ', ');
|
2010-02-24 02:39:05 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-03-12 04:34:57 +08:00
|
|
|
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);
|
2010-05-08 11:21:16 +08:00
|
|
|
},
|
|
|
|
eval: function () { return this }
|
2010-03-12 04:34:57 +08:00
|
|
|
};
|