2012-03-30 19:32:11 +00:00
|
|
|
# -*- coding: utf8 -*-
|
2012-03-18 14:21:58 +00:00
|
|
|
"""
|
2012-03-30 19:32:11 +00:00
|
|
|
.. module:: lesscpy.plib.deferred
|
|
|
|
:synopsis: Deferred mixin call.
|
|
|
|
|
|
|
|
Copyright (c)
|
|
|
|
See LICENSE for details.
|
|
|
|
.. moduleauthor:: Jóhann T. Maríusson <jtm@robot.is>
|
2012-03-18 14:21:58 +00:00
|
|
|
"""
|
|
|
|
from .node import Node
|
|
|
|
|
|
|
|
class Deferred(Node):
|
2012-04-07 11:33:07 +00:00
|
|
|
def __init__(self, mixin, args, lineno=0):
|
2012-03-30 19:32:11 +00:00
|
|
|
"""This node represents mixin calls
|
|
|
|
within the body of other mixins. The calls
|
|
|
|
to these mixins are deferred until the parent
|
|
|
|
mixin is called.
|
|
|
|
args:
|
|
|
|
mixin (Mixin): Mixin object
|
|
|
|
args (list): Call arguments
|
2012-03-18 14:21:58 +00:00
|
|
|
"""
|
2012-04-08 13:17:22 +00:00
|
|
|
self.tokens = [mixin, args]
|
2012-04-07 11:33:07 +00:00
|
|
|
self.lineno = lineno
|
2012-03-18 14:21:58 +00:00
|
|
|
|
2012-04-07 11:33:07 +00:00
|
|
|
def parse(self, scope, error=False):
|
2012-03-30 19:32:11 +00:00
|
|
|
""" Parse function.
|
|
|
|
args:
|
2012-04-03 13:36:08 +00:00
|
|
|
scope (Scope): Current scope
|
2012-03-30 19:32:11 +00:00
|
|
|
returns:
|
|
|
|
mixed
|
2012-03-18 14:21:58 +00:00
|
|
|
"""
|
2012-04-08 13:17:22 +00:00
|
|
|
mixin, args = self.tokens
|
|
|
|
if hasattr(mixin, 'call'):
|
|
|
|
return mixin.call(scope, args)
|
|
|
|
mixins = scope.mixins(mixin.raw())
|
2012-04-07 11:33:07 +00:00
|
|
|
if mixins:
|
|
|
|
for mixin in mixins:
|
2012-04-08 13:17:22 +00:00
|
|
|
res = mixin.call(scope, args)
|
2012-04-07 11:33:07 +00:00
|
|
|
if res: return res
|
|
|
|
else:
|
|
|
|
res = self
|
|
|
|
if error:
|
2012-04-08 13:17:22 +00:00
|
|
|
raise SyntaxError('NameError `%s`' % mixin.raw(True))
|
2012-04-07 14:38:52 +00:00
|
|
|
return res
|
2012-04-06 14:23:13 +00:00
|
|
|
|
2012-04-06 14:53:38 +00:00
|
|
|
def fmt(self, fills):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
return ''
|
|
|
|
|
2012-03-30 19:32:11 +00:00
|
|
|
|