From 1ada3c163a688e5ee94362f0cacd34116099a2a9 Mon Sep 17 00:00:00 2001 From: robotis Date: Mon, 4 Jun 2012 09:41:44 +0000 Subject: [PATCH] Reparse call nodes to refresh variables --- lesscpy/plib/call.py | 50 ++++++++++++++++------------------ lesscpy/test/css/calls.css | 4 +++ lesscpy/test/css/calls.min.css | 1 + lesscpy/test/less/calls.less | 9 +++++- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/lesscpy/plib/call.py b/lesscpy/plib/call.py index f57b24b..71c46d8 100644 --- a/lesscpy/plib/call.py +++ b/lesscpy/plib/call.py @@ -30,34 +30,32 @@ class Call(Node): args: scope (Scope): Current scope """ - if not self.parsed: - name = ''.join(self.tokens[0]) - parsed = self.process(self.tokens[1:], scope) + name = ''.join(self.tokens[0]) + parsed = self.process(self.tokens[1:], scope) - if name == '%(': - name = 'sformat' - elif name in ('~', 'e'): - name = 'escape' - color = Color.Color() - args = [t for t in parsed - if type(t) is not str or t not in '(),'] - if hasattr(self, name): + if name == '%(': + name = 'sformat' + elif name in ('~', 'e'): + name = 'escape' + color = Color.Color() + args = [t for t in parsed + if type(t) is not str or t not in '(),'] + if hasattr(self, name): + try: + return getattr(self, name)(*args) + except ValueError: + pass + + if hasattr(color, name): + try: + result = getattr(color, name)(*args) try: - return getattr(self, name)(*args) - except ValueError: - pass - - if hasattr(color, name): - try: - result = getattr(color, name)(*args) - try: - return result + ' ' - except TypeError: - return result - except ValueError: - pass - self.parsed = name + ''.join([p for p in parsed]) - return self.parsed + return result + ' ' + except TypeError: + return result + except ValueError: + pass + return name + ''.join([p for p in parsed]) def escape(self, string, *args): """Less Escape. diff --git a/lesscpy/test/css/calls.css b/lesscpy/test/css/calls.css index bb23446..d0f6aef 100644 --- a/lesscpy/test/css/calls.css +++ b/lesscpy/test/css/calls.css @@ -26,3 +26,7 @@ #colors { filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#333333', GradientType=1); } +a { + background-image: linear-gradient(top,#ffffff,#333333); + background-image: linear-gradient(top,#a6a6a6,#000000); +} diff --git a/lesscpy/test/css/calls.min.css b/lesscpy/test/css/calls.min.css index 056a35e..f5cb8c2 100644 --- a/lesscpy/test/css/calls.min.css +++ b/lesscpy/test/css/calls.min.css @@ -3,3 +3,4 @@ #format{format:"rgb(32, 128, 64)";format-string:"hello world";format-multiple:"hello earth 2";format-url-encode:'red is %23ff0000';} #more{width:1px;height:1px;top:50%;} #colors{filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#333333', GradientType=1);} +a{background-image:linear-gradient(top,#ffffff,#333333);background-image:linear-gradient(top,#a6a6a6,#000000);} diff --git a/lesscpy/test/less/calls.less b/lesscpy/test/less/calls.less index bb4d6a8..b420bc7 100644 --- a/lesscpy/test/less/calls.less +++ b/lesscpy/test/less/calls.less @@ -30,4 +30,11 @@ } #colors { filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)",#fff,#333)); -} \ No newline at end of file +} +#gradient(@startColor, @endColor) { + background-image: linear-gradient(top, @startColor, @endColor); +} +a { + #gradient(#fff, #333); + #gradient(#a6a6a6, #000); +}