carto/lib/less/tree/directive.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

(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);
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
};
})(require('less/tree'));