Selector matching

This commit is contained in:
Tom MacWright 2011-01-19 15:36:35 -05:00
parent 37292a0c22
commit 066ba365fc
3 changed files with 19 additions and 11 deletions

View File

@ -310,12 +310,20 @@ mess.Parser = function Parser(env) {
return function(options, variables) {
options = options || {};
options.compress = 'compress' in options ? options.compress : (env.compress || false);
options.compress = 'compress' in options ?
options.compress : (env.compress || false);
try {
var rulesets = this.flatten();
var mss = [];
rulesets.sort(specificitySort);
/*
for (var i in rulesets) {
if (rulesets[i].selectors[0].match('#red', [])) {
console.log(rulesets[i].toCSS([], env));
}
}
*/
for (var i = 0; i < rulesets.length; i++) {
mss.push(rulesets[i].toCSS([], env));
}

View File

@ -24,11 +24,10 @@ tree.Element.prototype.specificity = function() {
*/
tree.Element.prototype.toCSS = function(env) {
return this.combinator.toCSS() + this.value;
/*
* return this.value
.replace(/^\./, 'c-')
.replace(/^\#/, 'i-');
*/
};
tree.Element.prototype.match = function(id, classes) {
return (this.value in classes) || (this.value == id);
};
tree.Combinator = function(value) {

View File

@ -19,12 +19,13 @@ tree.Selector.prototype.specificity = function() {
}, [0, 0]).join(''));
};
tree.Selector.prototype.match = function(other) {
if (this.elements[0].value === other.elements[0].value) {
return true;
} else {
return false;
tree.Selector.prototype.match = function(id, classes) {
for (var i = 0; i < this.elements.length; i++) {
if (!this.elements[i].match(id, classes)) {
return false;
}
}
return true;
};
tree.Selector.prototype.toCSS = function(env) {