Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable storing of media queries in variables #776

Merged
merged 2 commits into from
Aug 7, 2012
Merged

Conversation

geddski
Copy link
Contributor

@geddski geddski commented Aug 7, 2012

It's common to reuse the same media queries throughout a stylesheet. It makes sense to use variables to keep track of these media queries, so you only have to update them in one place. Currently stylus ignores any variables used after the @media block. This change fixes that, so the following now works:

small = "screen and (min-width:1px) and (max-width:400px)"
@media small
  body
    background blue
@media screen and (min-width:1px) and (max-width:400px) {
  body {
    background: #00f;
  }
}

I've added a new test for this, and all other tests still pass.

@@ -188,6 +188,8 @@ Evaluator.prototype.visitReturn = function(ret){

Evaluator.prototype.visitMedia = function(media){
media.block = this.visit(media.block);
var query = this.lookup(media.val);
if(query) media.val = this.lookup("unquote").fn.call(this,query.nodes[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM tho we can just do if (query) media.val = new nodes.Literal(query.nodes[0].string) to avoid the lookup / .call

@geddski
Copy link
Contributor Author

geddski commented Aug 7, 2012

good idea, implemented.

tj added a commit that referenced this pull request Aug 7, 2012
enable storing of media queries in variables
@tj tj merged commit f61e61a into stylus:master Aug 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants