basic nested mixins

This commit is contained in:
robotis
2012-02-17 09:39:10 +00:00
parent 268eeb99ea
commit 21c824e0bb
6 changed files with 53 additions and 10 deletions

View File

@@ -366,7 +366,7 @@ class LessParser(object):
mixin = self.scope.mixins(n)
if mixin:
try:
p[0] = mixin.call(None)
p[0] = mixin.call(None, self.scope)
except SyntaxError as e:
self.handle_error(e, p)
p[0] = None
@@ -383,7 +383,7 @@ class LessParser(object):
p[0] = [b.parsed['proplist'] for b in l]
elif mixin:
try:
p[0] = mixin.call(None)
p[0] = mixin.call(None, self.scope)
except SyntaxError as e:
self.handle_error(e, p)
p[0] = None

View File

@@ -19,8 +19,9 @@ class Block(Process):
"""
self._blocktype = None
self.scope = scope
self._proplist()
# self._proplist()
self._pname()
self._proplist()
if self._name.startswith('@media'):
self._blocktype = 'inner'
self.parsed['identifier'] = self._ident.strip()
@@ -75,7 +76,10 @@ class Block(Process):
self.parsed['inner'] = []
for p in utility.flatten(self._p[2]):
if not p: continue
if not p.parsed: p.parse(self.scope)
if not p.parsed:
if type(p) is type(self):
self.scope.current = self._ident
p.parse(self.scope)
if type(p) is type(self):
self.parsed['inner'].append(p)
elif 'property' in p.parsed:

View File

@@ -33,7 +33,7 @@ class Mixin(Process):
else:
self.argv = []
self.argc = 0
self.prop = self._p[2]
self.nodes = self._p[2]
def call(self, args, scope=None):
""" Call mixin function.
@@ -46,12 +46,12 @@ class Mixin(Process):
if p]
self.scope = scope if scope else Scope(True)
self.scope[0]['__variables__'].update(self.stash)
prop = [copy.deepcopy(p) for p in self.prop if p]
prop = utility.flatten([p.call(args, self.scope)
if type(p) is Mixin else p
for p in prop])
nodes = [copy.deepcopy(p) for p in self.nodes if p]
nodes = utility.flatten([p.call(args, self.scope)
if type(p) is Mixin else p
for p in nodes])
self._process_args(args)
return [p.parse(self.scope) for p in prop]
return [p.parse(self.scope) for p in nodes]
def _process_args(self, args):
""" Process arguments to mixin call.

View File

@@ -0,0 +1,18 @@
.content {
width: 600px;
}
.content .column {
margin: 600px;
}
.content .column.blue {
color: blue;
}
.content-em {
width: 200px;
}
.content-em .column {
margin: 200px;
}
.content-em .column.blue {
color: blue;
}

View File

@@ -0,0 +1,6 @@
.content{width:600px;}
.content .column{margin:600px;}
.content .column.blue{color:blue;}
.content-em{width:200px;}
.content-em .column{margin:200px;}
.content-em .column.blue{color:blue;}

View File

@@ -0,0 +1,15 @@
.nested-ruleset (@width: 200px) {
width: @width;
.column {
margin: @width;
&.blue {
color: blue;
}
}
}
.content {
.nested-ruleset(600px);
}
.content-em {
.nested-ruleset();
}