remove evalRules, use eval

This commit is contained in:
cloudhead 2010-07-07 12:19:15 +02:00
parent e2b1a8af91
commit bf0198a029
3 changed files with 8 additions and 11 deletions

View File

@ -21,7 +21,7 @@ tree.Directive.prototype = {
},
eval: function (env) {
env.frames.unshift(this);
this.ruleset && this.ruleset.evalRules(env);
this.ruleset && this.ruleset.eval(env);
env.frames.shift();
return this;
},

View File

@ -16,7 +16,7 @@ tree.mixin.Call.prototype = {
if (mixins[m].match(this.arguments, env)) {
try {
Array.prototype.push.apply(
rules, mixins[m].eval(this.arguments, env).rules);
rules, mixins[m].eval(env, this.arguments).rules);
match = true;
} catch (e) {
throw { message: e.message, index: e.index, stack: e.stack, call: this.index };
@ -60,7 +60,7 @@ tree.mixin.Definition.prototype = {
find: function () { return this.parent.find.apply(this, arguments) },
rulesets: function () { return this.parent.rulesets.apply(this) },
eval: function (args, env) {
eval: function (env, args) {
var frame = new(tree.Ruleset)(null, []), context;
for (var i = 0, val; i < this.params.length; i++) {
@ -73,7 +73,7 @@ tree.mixin.Definition.prototype = {
}
}
}
return new(tree.Ruleset)(null, this.rules).evalRules({
return new(tree.Ruleset)(null, this.rules).eval({
frames: [this, frame].concat(this.frames, env.frames)
});
},

View File

@ -6,17 +6,14 @@ tree.Ruleset = function (selectors, rules) {
this._lookups = {};
};
tree.Ruleset.prototype = {
eval: function () { return this },
evalRules: function (context) {
eval: function (env) {
var rules = [];
this.rules.forEach(function (rule) {
if (rule.evalRules) {
rules.push(rule.evalRules(context));
} else if (rule instanceof tree.mixin.Call) {
Array.prototype.push.apply(rules, rule.eval(context));
if (rule instanceof tree.mixin.Call) {
Array.prototype.push.apply(rules, rule.eval(env));
} else if (! (rule instanceof tree.mixin.Definition)) {
rules.push(rule.eval ? rule.eval(context) : '');
rules.push(rule.eval ? rule.eval(env) : '');
}
});
this.rules = rules;