minor refactoring in rulesets output

This commit is contained in:
cloudhead 2010-03-05 11:42:52 -05:00
parent 76d4e08b30
commit 181712e662

View File

@ -38,12 +38,15 @@ tree.Ruleset.prototype = {
//
// Entry point for code generation
//
// `context` holds an array of arrays.
//
toCSS: function (context, env) {
var css = [], // The CSS output
rules = [], // node.Rule instances
rulesets = [], // node.Ruleset instances
paths = [], // Current selectors
selector; // The fully rendered selector
selector, // The fully rendered selector
rule;
if (! this.root) {
if (context.length === 0) {
@ -56,22 +59,29 @@ tree.Ruleset.prototype = {
}
}
}
// push the current ruleset to the frames stack
env.frames.unshift(this);
// Evaluate mixins
for (var i = 0; i < this.rules.length; i++) {
if (this.rules[i] instanceof tree.mixin.Call) {
Array.prototype.splice
.apply(this.rules, [i, 1].concat(this.rules[i].eval(env)));
}
}
// Evaluate rules and rulesets
for (var i = 0; i < this.rules.length; i++) {
if (this.rules[i] instanceof tree.Ruleset) {
rulesets.push(this.rules[i].toCSS(paths, env));
rule = this.rules[i];
if (rule instanceof tree.Ruleset ||
(rule instanceof tree.Directive && rule.rules)) {
rulesets.push(rule.toCSS(paths, env));
} else {
if (this.rules[i].toCSS && !this.rules[i].variable) {
rules.push(this.rules[i].toCSS(env));
} else if (this.rules[i].value && !this.rules[i].variable) {
rules.push(this.rules[i].value.toString());
if (rule.toCSS && !rule.variable) {
rules.push(rule.toCSS(env));
} else if (rule.value && !rule.variable) {
rules.push(rule.value.toString());
}
}
}