improve import support with media features

This commit is contained in:
Alexis Sellier
2012-01-05 21:31:39 +01:00
parent d8441445a5
commit 7dd31ff654
6 changed files with 14 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ tree.Directive = function (name, value, features) {
if (Array.isArray(value)) {
this.ruleset = new(tree.Ruleset)([], value);
this.ruleset.allowImports = true;
} else {
this.value = value;
}

View File

@@ -57,13 +57,12 @@ tree.Import.prototype = {
}
},
eval: function (env) {
var ruleset;
var ruleset, features = this.features && this.features.eval(env);
if (this.css) {
this.features = this.features && this.features.eval(env);
return this;
} else {
ruleset = new(tree.Ruleset)(null, this.root.rules.slice(0));
ruleset = new(tree.Ruleset)([], this.root.rules.slice(0));
for (var i = 0; i < ruleset.rules.length; i++) {
if (ruleset.rules[i] instanceof tree.Import) {
@@ -73,7 +72,7 @@ tree.Import.prototype = {
[i, 1].concat(ruleset.rules[i].eval(env)));
}
}
return ruleset.rules;
return this.features ? new(tree.Directive)('@media', ruleset.rules, this.features.value) : ruleset.rules;
}
}
};

View File

@@ -11,12 +11,13 @@ tree.Ruleset.prototype = {
var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0));
ruleset.root = this.root;
ruleset.allowImports = this.allowImports;
// push the current ruleset to the frames stack
env.frames.unshift(ruleset);
// Evaluate imports
if (ruleset.root) {
if (ruleset.root || ruleset.allowImports) {
for (var i = 0; i < ruleset.rules.length; i++) {
if (ruleset.rules[i] instanceof tree.Import) {
Array.prototype.splice

5
test/css/import.css vendored
View File

@@ -16,3 +16,8 @@
width: 10px;
height: 30%;
}
@media screen and (max-width: 600px) {
body {
width: 100%;
}
}

View File

@@ -8,3 +8,4 @@
width: 10px;
height: @a + 10%;
}
@import "import/import-test-e" screen and (max-width: 600px);

View File

@@ -0,0 +1,2 @@
body { width: 100% }