Fix dynamic mixins with nested rules

Dynamic mixins with more than one level of nesting wouldn't work.
This is now fixed. Also refactored mixin.definition.eval a little.
This commit is contained in:
cloudhead
2010-04-22 13:07:41 -04:00
parent 1e0cfe9ac1
commit 25dbfb177a
5 changed files with 31 additions and 7 deletions

View File

@@ -45,13 +45,8 @@ tree.mixin.Definition.prototype = {
context = { frames: [this, frame].concat(env.frames) };
return new(tree.Ruleset)(null, this.rules.map(function (rule) {
if (rule.rules) {
return new(tree.Ruleset)(rule.selectors, rule.rules.map(function (r) {
return new(tree.Rule)(r.name, r.value.eval(context));
}));
} else {
return new(tree.Rule)(rule.name, rule.value.eval(context));
}
if (rule.evalRules) return rule.evalRules(context);
else return rule.eval(context);
}));
}
};

View File

@@ -16,6 +16,10 @@ tree.Rule.prototype.toCSS = function (env) {
}
};
tree.Rule.prototype.eval = function (context) {
return new(tree.Rule)(this.name, this.value.eval(context));
};
tree.Value = function Value(value) {
this.value = value;
this.is = 'value';

View File

@@ -7,6 +7,12 @@ tree.Ruleset = function Ruleset(selectors, rules) {
};
tree.Ruleset.prototype = {
eval: function () { return this },
evalRules: function (context) {
return new(tree.Ruleset)(this.selectors, this.rules.map(function (r) {
if (r.evalRules) return r.evalRules(context);
else return r.eval(context);
}));
},
variables: function () {
if (this._variables) { return this._variables }
else {

View File

@@ -0,0 +1,6 @@
.class .inner {
height: 300;
}
.class .inner .innest {
width: 30;
}

View File

@@ -0,0 +1,13 @@
.mix (@a: 10) {
.inner {
height: @a * 10;
.innest {
width: @a;
}
}
}
.class {
.mix(30);
}