From 11895c7e30c2eed3d298acc59713be2b69b079e8 Mon Sep 17 00:00:00 2001 From: Sascha Peilicke Date: Thu, 5 Sep 2013 14:04:22 +0200 Subject: [PATCH] Support variables inside @media identifiers This solution is somewhat hacky, the @media element really deserves a Node subclass and it's own parsing rules. What's still missing is LESS variables in grouped media queries like: @singleQuery: ~"(max-width: 500px)"; @media screen, @singleQuery { set { padding: 3 3 3 3; } } Fixes #18 --- lesscpy/lessc/parser.py | 8 ++++++++ lesscpy/test/css/media.css | 5 +++++ lesscpy/test/css/media.min.css | 1 + lesscpy/test/less/media.less | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/lesscpy/lessc/parser.py b/lesscpy/lessc/parser.py index c491c22..ab2cb44 100644 --- a/lesscpy/lessc/parser.py +++ b/lesscpy/lessc/parser.py @@ -514,6 +514,14 @@ class LessParser(object): """ p[0] = list(p)[1:] + def p_ident_media_var(self, p): + """ ident_parts : css_media t_ws t_popen word ':' variable t_pclose + """ + p[0] = list(p)[1:] + if utility.is_variable(p[0][5]): + var = self.scope.variables(''.join(p[0][5])) + p[0][5] = var.value[0] + def p_selector(self, p): """ selector : '*' | '+' diff --git a/lesscpy/test/css/media.css b/lesscpy/test/css/media.css index 258e891..217091f 100644 --- a/lesscpy/test/css/media.css +++ b/lesscpy/test/css/media.css @@ -34,3 +34,8 @@ display: none !important; } } +@media (min-width:12px) { + body { + margin: 0 auto; + } +} diff --git a/lesscpy/test/css/media.min.css b/lesscpy/test/css/media.min.css index da1940b..0697ad0 100644 --- a/lesscpy/test/css/media.min.css +++ b/lesscpy/test/css/media.min.css @@ -6,3 +6,4 @@ body{max-width:35em;margin:0 auto;}} @media screen{body{max-width:480;}} @media all and (orientation:portrait){aside{float:none;}} @media (min-width:768px)and (max-width: 979px){.hidden-desktop{display:none !important;}} +@media (min-width:12px){body{margin:0 auto;}} diff --git a/lesscpy/test/less/media.less b/lesscpy/test/less/media.less index fd88365..f5696cd 100644 --- a/lesscpy/test/less/media.less +++ b/lesscpy/test/less/media.less @@ -42,3 +42,8 @@ @media (min-width: 768px) and (max-width: 979px) { .hidden-desktop { display: none !important; } } + +@minwidth: 12px; +@media (min-width: @minwidth) { + body { margin: 0 auto; } +}