2011-01-18 03:46:22 +08:00
|
|
|
(function(tree) {
|
|
|
|
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
|
|
|
|
2011-01-18 03:46:22 +08:00
|
|
|
tree.Rule.prototype.toCSS = function(env) {
|
2010-12-14 07:28:49 +08:00
|
|
|
if (!tree.Reference.validSelector(this.name)) {
|
|
|
|
throw {
|
2011-01-18 03:46:22 +08:00
|
|
|
message: 'Unrecognized selector: ' + this.name,
|
2010-12-14 07:28:49 +08:00
|
|
|
index: this.index
|
2011-01-19 03:26:57 +08:00
|
|
|
};
|
2010-12-14 07:28:49 +08:00
|
|
|
}
|
2011-01-15 07:42:58 +08:00
|
|
|
|
|
|
|
if (!tree.Reference.validValue(env, this.name, this.value)) {
|
2010-12-14 08:10:18 +08:00
|
|
|
throw {
|
2011-01-18 03:46:22 +08:00
|
|
|
message: 'Invalid value for ' +
|
2010-12-14 11:48:10 +08:00
|
|
|
this.name +
|
2011-01-18 03:46:22 +08:00
|
|
|
', a ' +
|
2010-12-14 11:48:10 +08:00
|
|
|
tree.Reference.selector(this.name).type +
|
2011-01-18 03:46:22 +08:00
|
|
|
' is expected',
|
2010-12-14 08:10:18 +08:00
|
|
|
index: this.index
|
2011-01-19 03:26:57 +08:00
|
|
|
};
|
2010-12-14 08:10:18 +08:00
|
|
|
}
|
2010-12-14 07:28:49 +08:00
|
|
|
|
2011-01-18 03:46:22 +08:00
|
|
|
if (this.variable) { return '' }
|
2010-02-26 06:56:21 +08:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2011-01-18 03:46:22 +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
|
|
|
};
|
|
|
|
|
2011-01-18 03:46:22 +08:00
|
|
|
tree.Shorthand = function(a, b) {
|
2010-03-12 04:34:57 +08:00
|
|
|
this.a = a;
|
|
|
|
this.b = b;
|
|
|
|
};
|
|
|
|
|
|
|
|
tree.Shorthand.prototype = {
|
2011-01-18 03:46:22 +08:00
|
|
|
toCSS: function(env) {
|
|
|
|
return this.a.toCSS(env) + '/' + this.b.toCSS(env);
|
2010-05-08 11:21:16 +08:00
|
|
|
},
|
2011-01-18 03:46:22 +08:00
|
|
|
eval: function() { return this }
|
2010-03-12 04:34:57 +08:00
|
|
|
};
|
2010-06-16 06:44:59 +08:00
|
|
|
|
2011-01-06 03:23:28 +08:00
|
|
|
})(require('mess/tree'));
|