How to use the lesscpy.plib.expression.Expression function in lesscpy

To help you get started, we’ve selected a few lesscpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lesscpy / lesscpy / test / test_expression.py View on Github external
def test_op(self):
        for test in [
            ['0', '=', '0', True],
            ['1', '>', '2', False],
            ['1', '<', '2', True],
            ['1', '>=', '2', False],
            ['1', '=<', '2', True],
        ]:
            e = Expression(test[:3])
            self.assertEqual(test[3], e.parse(None), test)
github lesscpy / lesscpy / test / test_expression.py View on Github external
def test_basic(self):
        for test in [
            ['0', '+', '0', '0'],
            ['2', '+', '2', '4'],
            ['2.0', '+', '2', '4'],
            ['2', '+', '2.0', '4'],
            ['2.0', '+', '2.0', '4'],
            [('2.0', ), '+', '2.0', '4'],
            [('2.0', ), '+', ('2.0', ), '4'],
            ['0px', '+', '0', '0'],
            ['2px', '+', '2', '4px'],
            ['2.0px', '+', '2', '4px'],
            [('2px', ' '), '+', '2.0', '4px'],
            ['2.0px', '+', '2.0', '4px'],
        ]:
            e = Expression(test[:3])
            self.assertEqual(test[3], e.parse(None), str(test))
github lesscpy / lesscpy / test / test_expression.py View on Github external
['-2', '+', '-2', '-4'],
            ['-2.0', '+', '-2', '-4'],
            ['-2', '+', '-2.0', '-4'],
            ['-2.0', '+', '-2.0', '-4'],
            ['-0', '-', '0', '0'],
            ['-2', '-', '-2', '0'],
            ['-2.0', '-', '2', '-4'],
            ['-2', '-', '-2.0', '0'],
            ['2.0', '-', '-2.0', '4'],
            ['-0px', '+', '0', '0'],
            ['-2px', '+', '-2', '-4px'],
            ['-2.0', '+', '-2px', '-4px'],
            ['-2em', '+', '-2.0', '-4em'],
            ['-2.0s', '+', '-2.0s', '-4s'],
        ]:
            e = Expression(test[:3])
            self.assertEqual(test[3], e.parse(None), str(test))
github lesscpy / lesscpy / lesscpy / plib / mixin.py View on Github external
def parse_guards(self, scope):
        """Parse guards on mixin.
        args:
            scope (Scope): current scope
        raises:
            SyntaxError
        returns:
            bool (passes guards)
        """
        if self.guards:
            cor = True if ',' in self.guards else False
            for g in self.guards:
                if isinstance(g, list):
                    res = (g[0].parse(scope)
                           if len(g) == 1 else Expression(g).parse(scope))
                    if cor:
                        if res:
                            return True
                    elif not res:
                        return False
        return True
github lesscpy / lesscpy / lesscpy / plib / mixin.py View on Github external
def call(self, scope, args=[]):
        """Call mixin. Parses a copy of the mixins body
        in the current scope and returns it.
        args:
            scope (Scope): current scope
            args (list): arguments
        raises:
            SyntaxError
        returns:
            list or False
        """
        ret = False
        if args:
            args = [[
                a.parse(scope) if isinstance(a, Expression) else a for a in arg
            ] if arg else arg for arg in args]
        try:
            self.parse_args(args, scope)
        except SyntaxError:
            pass
        else:
            if self.parse_guards(scope):
                body = self.body.copy()
                ret = body.tokens[1]
                if ret:
                    utility.rename(ret, scope, Block)
        return ret