2010-06-16 06:44:59 +08:00
|
|
|
(function (tree) {
|
2010-06-28 04:40:12 +08:00
|
|
|
tree.Rule = function (name, value, important, index) {
|
2010-02-24 02:39:05 +08:00
|
|
|
this.name = name;
|
2010-12-14 07:28:49 +08:00
|
|
|
this.value = (value instanceof tree.Value) ?
|
|
|
|
value : new(tree.Value)([value]);
|
2010-06-28 04:40:12 +08:00
|
|
|
this.important = important ? ' ' + important.trim() : '';
|
2010-06-08 03:47:41 +08:00
|
|
|
this.index = index;
|
2010-12-14 11:48:10 +08:00
|
|
|
this.symbolizer = tree.Reference.symbolizer(this.name);
|
2010-02-24 02:39:05 +08:00
|
|
|
|
|
|
|
if (name.charAt(0) === '@') {
|
|
|
|
this.variable = true;
|
|
|
|
} else { this.variable = false }
|
|
|
|
};
|
2010-12-14 07:28:49 +08:00
|
|
|
|
2010-06-12 09:45:51 +08:00
|
|
|
tree.Rule.prototype.toCSS = function (env) {
|
2010-12-14 07:28:49 +08:00
|
|
|
if (!tree.Reference.validSelector(this.name)) {
|
|
|
|
throw {
|
|
|
|
message: "Unrecognized selector: " + this.name,
|
|
|
|
index: this.index
|
|
|
|
};
|
|
|
|
}
|
2010-12-14 08:10:18 +08:00
|
|
|
if (!tree.Reference.validValue(this.name, this.value)) {
|
|
|
|
throw {
|
2010-12-14 11:48:10 +08:00
|
|
|
message: "Invalid type of value for rule " +
|
|
|
|
this.name +
|
|
|
|
", value type " +
|
|
|
|
tree.Reference.selector(this.name).type +
|
|
|
|
" expected",
|
2010-12-14 08:10:18 +08:00
|
|
|
index: this.index
|
|
|
|
};
|
|
|
|
}
|
2010-12-14 07:28:49 +08:00
|
|
|
|
2010-02-26 06:56:21 +08:00
|
|
|
if (this.variable) { return "" }
|
|
|
|
else {
|
2011-01-05 07:51:12 +08:00
|
|
|
return tree.Reference.selectorName(this.name) +
|
|
|
|
'="' +
|
2010-12-14 08:10:18 +08:00
|
|
|
this.value.toCSS(env, this.name) +
|
2011-01-05 07:51:12 +08:00
|
|
|
'"';
|
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) {
|
2010-12-14 07:28:49 +08:00
|
|
|
return new(tree.Rule)(this.name,
|
|
|
|
this.value.eval(context),
|
|
|
|
this.important,
|
|
|
|
this.index);
|
2010-04-23 01:07:41 +08:00
|
|
|
};
|
|
|
|
|
2010-06-19 13:51:26 +08:00
|
|
|
tree.Shorthand = function (a, b) {
|
2010-03-12 04:34:57 +08:00
|
|
|
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
|
|
|
};
|
2010-06-16 06:44:59 +08:00
|
|
|
|
|
|
|
})(require('less/tree'));
|