2010-06-16 06:44:59 +08:00
|
|
|
(function (tree) {
|
2010-02-24 02:39:05 +08:00
|
|
|
|
2010-06-19 13:51:26 +08:00
|
|
|
tree.Directive = function (name, value) {
|
2010-02-24 02:39:05 +08:00
|
|
|
this.name = name;
|
|
|
|
if (Array.isArray(value)) {
|
2010-05-24 00:50:20 +08:00
|
|
|
this.ruleset = new(tree.Ruleset)([], value);
|
2010-02-24 02:39:05 +08:00
|
|
|
} else {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
};
|
2010-05-24 00:50:20 +08:00
|
|
|
tree.Directive.prototype = {
|
|
|
|
toCSS: function (ctx, env) {
|
|
|
|
if (this.ruleset) {
|
|
|
|
this.ruleset.root = true;
|
2010-06-12 09:45:51 +08:00
|
|
|
return this.name + (env.compress ? '{' : ' {\n ') +
|
|
|
|
this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
|
|
|
|
(env.compress ? '}': '\n}\n');
|
2010-05-24 00:50:20 +08:00
|
|
|
} else {
|
|
|
|
return this.name + ' ' + this.value.toCSS() + ';\n';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
eval: function (env) {
|
|
|
|
env.frames.unshift(this);
|
2010-07-24 07:46:48 +08:00
|
|
|
this.ruleset = this.ruleset && this.ruleset.eval(env);
|
2010-05-24 00:50:20 +08:00
|
|
|
env.frames.shift();
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
|
|
|
|
find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
|
|
|
|
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) }
|
2010-02-24 02:39:05 +08:00
|
|
|
};
|
2010-06-16 06:44:59 +08:00
|
|
|
|
|
|
|
})(require('less/tree'));
|