2010-03-02 04:32:21 +08:00
|
|
|
if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); }
|
2010-02-24 02:39:05 +08:00
|
|
|
|
2010-03-02 04:32:21 +08:00
|
|
|
tree.Rule = function Rule(name, value) {
|
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-02-24 02:39:05 +08:00
|
|
|
|
|
|
|
if (name.charAt(0) === '@') {
|
|
|
|
this.variable = true;
|
|
|
|
} else { this.variable = false }
|
|
|
|
};
|
2010-03-02 04:32:21 +08:00
|
|
|
tree.Rule.prototype.toCSS = function (env) {
|
2010-02-26 06:56:21 +08:00
|
|
|
if (this.variable) { return "" }
|
|
|
|
else {
|
|
|
|
return this.name + ": " +
|
|
|
|
(this.value.toCSS ? this.value.toCSS(env) : this.value) + ";";
|
|
|
|
}
|
2010-02-24 02:39:05 +08:00
|
|
|
};
|
|
|
|
|
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-02 04:32:21 +08:00
|
|
|
tree.Value.prototype.eval = function (env) {
|
2010-02-24 02:39:05 +08:00
|
|
|
if (this.value.length === 1) {
|
|
|
|
return this.value[0].eval(env);
|
|
|
|
} else {
|
2010-03-06 02:32:07 +08:00
|
|
|
return this;
|
2010-02-24 02:39:05 +08:00
|
|
|
}
|
|
|
|
};
|
2010-03-02 04:32:21 +08:00
|
|
|
tree.Value.prototype.toCSS = function (env) {
|
2010-02-24 02:39:05 +08:00
|
|
|
return this.value.map(function (e) {
|
|
|
|
return e.toCSS ? e.toCSS(env) : e;
|
|
|
|
}).join(', ');
|
|
|
|
};
|
|
|
|
|