mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
support CSS3 @media more fully
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user