Skip to content

Commit

Permalink
added @media bubbling (similar to SASS)
Browse files Browse the repository at this point in the history
  • Loading branch information
NDMarcel committed Feb 14, 2012
1 parent d17a461 commit 288248d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/less/tree/directive.js
@@ -1,11 +1,14 @@
(function (tree) {

tree.Directive = function (name, value, features) {
var selectors;

this.name = name;
this.features = features && new(tree.Value)(features);

if (Array.isArray(value)) {
this.ruleset = new(tree.Ruleset)([], value);
selectors = name === '@media' ? [new(tree.Selector)([new(tree.Element)("", null, 0)])] : [];
this.ruleset = new(tree.Ruleset)(selectors, value);
this.ruleset.allowImports = true;
} else {
this.value = value;
Expand All @@ -16,7 +19,7 @@ tree.Directive.prototype = {
var features = this.features ? ' ' + this.features.toCSS(env) : '';

if (this.ruleset) {
this.ruleset.root = true;
this.ruleset.root = ctx.length === 0 || (this.name !== '@media');
return this.name + features + (env.compress ? '{' : ' {\n ') +
this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
(env.compress ? '}': '\n}\n');
Expand Down
5 changes: 5 additions & 0 deletions test/css/media.css
Expand Up @@ -25,3 +25,8 @@
max-width: 480px;
}
}
@media print {
body {
padding: 20px;
}
}
8 changes: 7 additions & 1 deletion test/less/media.less
Expand Up @@ -5,7 +5,7 @@

@media print {
.class {
color: blue;
color: blue;
.sub {
width: @var;
}
Expand All @@ -29,3 +29,9 @@
max-width: 480px;
}
}

body {
@media print {
padding: 20px;
}
}

0 comments on commit 288248d

Please sign in to comment.