From db72420ca06e637729b65bf2db02346810fafcfd Mon Sep 17 00:00:00 2001 From: jtm Date: Sun, 18 Mar 2012 10:30:25 +0000 Subject: [PATCH] nested mixing-args --- lesscpy/plib/mixin.py | 6 +- lesscpy/test/css/elements.css | 1 - lesscpy/test/css/elements.min.css | 1 - lesscpy/test/css/mixin-args-nested.css | 59 +++++++++++++++++++ lesscpy/test/css/mixin-args-nested.min.css | 19 ++++++ lesscpy/test/css/mixin-args.css | 6 ++ lesscpy/test/css/mixin-args.min.css | 2 + lesscpy/test/css/mixin-blocks.css | 3 + lesscpy/test/css/mixin-blocks.min.css | 1 + lesscpy/test/less/mixin-args-nested.less | 68 ++++++++++++++++++++++ lesscpy/test/testless.py | 4 ++ 11 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 lesscpy/test/css/mixin-args-nested.css create mode 100644 lesscpy/test/css/mixin-args-nested.min.css create mode 100644 lesscpy/test/less/mixin-args-nested.less diff --git a/lesscpy/plib/mixin.py b/lesscpy/plib/mixin.py index a5c6083..b4fcb1e 100644 --- a/lesscpy/plib/mixin.py +++ b/lesscpy/plib/mixin.py @@ -28,14 +28,16 @@ class Mixin(Node): args = args if type(args) is list else [args] vars = [] for arg, var in itertools.zip_longest([a for a in args if a != ','], parsed): + if arg is None and utility.is_variable(var): + raise SyntaxError('Missing argument to mixin') if arg == var and utility.is_variable(arg): continue - elif type(var) is Variable: - if arg: var.value = arg elif utility.is_variable(arg): tmp = scope.variables(arg) if not tmp: continue var = Variable([var, None, tmp.name]).parse(scope) + elif type(var) is Variable: + if arg: var.value = arg elif utility.is_variable(var): var = Variable([var, None, arg]).parse(scope) else: continue diff --git a/lesscpy/test/css/elements.css b/lesscpy/test/css/elements.css index 8b13789..e69de29 100644 --- a/lesscpy/test/css/elements.css +++ b/lesscpy/test/css/elements.css @@ -1 +0,0 @@ - diff --git a/lesscpy/test/css/elements.min.css b/lesscpy/test/css/elements.min.css index 8b13789..e69de29 100644 --- a/lesscpy/test/css/elements.min.css +++ b/lesscpy/test/css/elements.min.css @@ -1 +0,0 @@ - diff --git a/lesscpy/test/css/mixin-args-nested.css b/lesscpy/test/css/mixin-args-nested.css new file mode 100644 index 0000000..8e57d04 --- /dev/null +++ b/lesscpy/test/css/mixin-args-nested.css @@ -0,0 +1,59 @@ +#e { + radius: 5px; +} +#j { + radius: 5px; +} +#k { + radius: 1px; +} +.content { + width: 600px; +} +.content .column { + margin: 600px; +} +.content .column.blue { + color: blue; +} +.content .column.blue .deep { + padding: 600px; +} +.content-em { + width: 200px; +} +.content-em .column { + margin: 200px; +} +.content-em .column.blue { + color: blue; +} +.content-em .column.blue .deep { + padding: 200px; +} +.test-2 { + width: 300px; + width: 300px; +} +.test-2 .column { + margin: 300px; +} +.test-2 .column.blue { + color: blue; +} +.test-2 .column.blue .deep { + padding: 300px; +} +.test-2-em { + width: 600px; + width: 600px; +} +.test-2-em .column { + margin: 600px; +} +.test-2-em .column.blue { + color: blue; +} +.test-2-em .column.blue .deep { + padding: 600px; +} diff --git a/lesscpy/test/css/mixin-args-nested.min.css b/lesscpy/test/css/mixin-args-nested.min.css new file mode 100644 index 0000000..9a5c98a --- /dev/null +++ b/lesscpy/test/css/mixin-args-nested.min.css @@ -0,0 +1,19 @@ +#e{radius:5px;} +#j{radius:5px;} +#k{radius:1px;} +.content{width:600px;} +.content .column{margin:600px;} +.content .column.blue{color:blue;} +.content .column.blue .deep{padding:600px;} +.content-em{width:200px;} +.content-em .column{margin:200px;} +.content-em .column.blue{color:blue;} +.content-em .column.blue .deep{padding:200px;} +.test-2{width:300px;width:300px;} +.test-2 .column{margin:300px;} +.test-2 .column.blue{color:blue;} +.test-2 .column.blue .deep{padding:300px;} +.test-2-em{width:600px;width:600px;} +.test-2-em .column{margin:600px;} +.test-2-em .column.blue{color:blue;} +.test-2-em .column.blue .deep{padding:600px;} diff --git a/lesscpy/test/css/mixin-args.css b/lesscpy/test/css/mixin-args.css index 9515b8f..badeed0 100644 --- a/lesscpy/test/css/mixin-args.css +++ b/lesscpy/test/css/mixin-args.css @@ -56,3 +56,9 @@ .arguments4 { border: 1px solid red; } +.div :-moz-placeholder { + color: #ffffff; +} +.div :-moz-placeholder::-webkit-input-placeholder { + color: #ffffff; +} diff --git a/lesscpy/test/css/mixin-args.min.css b/lesscpy/test/css/mixin-args.min.css index aa4aaec..98b2273 100644 --- a/lesscpy/test/css/mixin-args.min.css +++ b/lesscpy/test/css/mixin-args.min.css @@ -14,3 +14,5 @@ .arguments3{border:0px;} .arguments3{border:1px solid red;} .arguments4{border:1px solid red;} +.div :-moz-placeholder{color:#ffffff;} +.div :-moz-placeholder::-webkit-input-placeholder{color:#ffffff;} diff --git a/lesscpy/test/css/mixin-blocks.css b/lesscpy/test/css/mixin-blocks.css index bb3d13a..db4888c 100644 --- a/lesscpy/test/css/mixin-blocks.css +++ b/lesscpy/test/css/mixin-blocks.css @@ -76,3 +76,6 @@ div.nest a:hover .deep p, div.nest a:focus .deep p { border-color: orange; background-color: grey; } +.secure-zone { + color: transparent; +} diff --git a/lesscpy/test/css/mixin-blocks.min.css b/lesscpy/test/css/mixin-blocks.min.css index 91ca850..2f623a2 100644 --- a/lesscpy/test/css/mixin-blocks.min.css +++ b/lesscpy/test/css/mixin-blocks.min.css @@ -22,3 +22,4 @@ div.nest a:hover .deep p,div.nest a:focus .deep p{widows:3;} #header #cookie{border-style:dashed;} #header #cookie .chips{border-style:dotted;} #header #cookie .chips .calories{color:black;border-color:orange;background-color:grey;} +.secure-zone{color:transparent;} diff --git a/lesscpy/test/less/mixin-args-nested.less b/lesscpy/test/less/mixin-args-nested.less new file mode 100644 index 0000000..f463d04 --- /dev/null +++ b/lesscpy/test/less/mixin-args-nested.less @@ -0,0 +1,68 @@ +/* + Args nested +*/ +.a(@radius) { + radius: @radius; +} +.b(@radius) { + .a(@radius); +} +.c(@radius) { + .b(@radius); +} +.d(@radius) { + .c(@radius); +} +#e { + .d(5px); +} +// kwarg +.f(@radius: 1px) { + radius: @radius; +} +.g(@radius) { + .f(@radius); +} +.h(@radius) { + .g(@radius); +} +.i(@radius: 1px) { + .h(@radius); +} +#j { + .i(5px); +} +#k { + .i(); +} +// +// Nested +// +.nested-ruleset (@width: 200px) { + width: @width; + .column { + margin: @width; + &.blue { + color: blue; + .deep { + padding: @width; + } + } + } +} +.content { + .nested-ruleset(600px); +} +.content-em { + .nested-ruleset(); +} +.nested-2(@width: 300px) { + width: @width; + .nested-ruleset(@width); +} +.test-2 { + .nested-2(); +} +.test-2-em { + .nested-2(600px); +} diff --git a/lesscpy/test/testless.py b/lesscpy/test/testless.py index 073ffa9..0488115 100644 --- a/lesscpy/test/testless.py +++ b/lesscpy/test/testless.py @@ -27,6 +27,8 @@ def create_test (args): if not line: continue self.assertEqual(line, pout[i], '%s: Line %d' % (cssf, i+1)) i += 1 + if len(pout) > i and i: + self.fail("%s: result has more lines (%d < %d)" % (cssf, i, len(pout))) else: self.fail("%s not found..." % cssf) if os.path.exists(minf): @@ -39,6 +41,8 @@ def create_test (args): for line in cssf.readlines(): self.assertEqual(line.rstrip(), mout[i], '%s: Line %d' % (minf, i+1)) i += 1 + if len(mout) > i and i: + self.fail("%s: result has more lines (%d < %d)" % (minf, i, len(mout))) else: self.fail("%s not found..." % minf) return do_test_expected