carto/lib/less/tree/rule.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

(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;
this.value = (value instanceof tree.Value) ?
value : new(tree.Value)([value]);
2010-06-28 04:40:12 +08:00
this.important = important ? ' ' + important.trim() : '';
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-06-12 09:45:51 +08:00
tree.Rule.prototype.toCSS = function (env) {
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-02-26 06:56:21 +08:00
if (this.variable) { return "" }
else {
return '<CssParameter name="' +
2010-12-14 08:10:18 +08:00
tree.Reference.selectorName(this.name) +
'">' +
this.value.toCSS(env, this.name) +
'</CssParameter>';
2010-02-26 06:56:21 +08:00
}
2010-02-24 02:39:05 +08:00
};
tree.Rule.prototype.eval = function (context) {
return new(tree.Rule)(this.name,
this.value.eval(context),
this.important,
this.index);
};
2010-06-19 13:51:26 +08:00
tree.Shorthand = function (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 }
};
})(require('less/tree'));