support CSS3 @media more fully

This commit is contained in:
cloudhead
2010-05-22 18:24:37 -04:00
parent d6934147d9
commit f35d035e51
3 changed files with 14 additions and 10 deletions

View File

@@ -769,7 +769,7 @@ less.Parser = function Parser(env) {
if (value = $(this['import'])) {
return value;
} else if (name = $(/@media|@page/g)) {
types = $(/[a-z:, ]+/g).trim();
types = $(/[^{]+/g).trim();
if (rules = $(this.block)) {
return new(tree.Directive)(name + " " + types, rules);
}

View File

@@ -3,19 +3,21 @@ if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
tree.Directive = function Directive(name, value) {
this.name = name;
if (Array.isArray(value)) {
this.rules = value;
this.rules = new(tree.Ruleset)([], value);
} else {
this.value = value;
}
};
tree.Directive.prototype.toCSS = function () {
tree.Directive.prototype.toCSS = function (ctx, env) {
if (this.rules) {
return this.name + " {\n " +
this.rules.map(function (r) {
return r.toCSS();
}).join("\n ") + "\n}\n";
this.rules.root = true;
return this.name + ' {\n ' +
this.rules.toCSS(ctx, env).trim().replace(/\n/g, '\n ') + '\n}\n';
} else {
return this.name + ' ' + this.value.toCSS() + ';\n';
}
};
tree.Directive.prototype.eval = function () { return this }
tree.Directive.prototype.eval = function (env) {
this.rules && this.rules.evalRules(env);
return this;
}

View File

@@ -116,7 +116,9 @@ tree.Ruleset.prototype = {
for (var i = 0; i < this.rules.length; i++) {
rule = this.rules[i];
if (rule.rules) {
if (rule instanceof tree.Directive) {
rulesets.push(rule.eval(env).toCSS(paths, env));
} else if (rule.rules) {
rulesets.push(rule.toCSS(paths, env));
} else if (rule instanceof tree.Comment) {
if (this.root) {
@@ -154,7 +156,7 @@ tree.Ruleset.prototype = {
// Pop the stack
env.frames.shift();
paths.forEach(function (p) { p.pop() });
while (p.length) { p.pop() }
return css.join('');
}