Example #1
0
    def compile(self, token, options = cssparser.CSSOptions()):
        if token.isRuleSet():
            self.pushScope()

        if token.isAtRule():
            self.compileAtRule(token, options)
            if token.parent == None: # the token could have been removed
                return

        i = 0
        while i < len(token.children):
            child = token.children[i]
            if child.parent == None:
                raise SCSSCompileError("Child is looking for its parents, please report at the tent next to the main stage", child)
            self.compile(child, options)
            if child.parent: # the token could have been removed
                i += 1

        if token.isAnyToken():
            self.compileAny(token)
        elif token.isValue():
            self.compileValue(token)
        elif token.isDeclaration():
            self.compileDeclaration(token)
        elif token.isAssignment():
            SCSSExpression.processAssignment(token, self.getCurrentScope())
        elif token.isRuleSet():
            self.compileRuleSet(token)
            self.popScope()
        elif token.isAtRule() and token.getKeyWord() == "extend":
            self.processExtend(token)
        elif token.isAtRule() and token.getKeyWord() == "media":
            self.processMediaQuery(token)
Example #2
0
    def compile(self, token, options=cssparser.CSSOptions()):
        if token.isRuleSet():
            self.pushScope()

        if token.isAtRule():
            self.compileAtRule(token, options)
            if token.parent == None:  # the token could have been removed
                return

        i = 0
        while i < len(token.children):
            child = token.children[i]
            if child.parent == None:
                raise SCSSCompileError(
                    "Child is looking for its parents, please report at the tent next to the main stage",
                    child)
            self.compile(child, options)
            if child.parent:  # the token could have been removed
                i += 1

        if token.isAnyToken():
            self.compileAny(token)
        elif token.isValue():
            self.compileValue(token)
        elif token.isDeclaration():
            self.compileDeclaration(token)
        elif token.isAssignment():
            SCSSExpression.processAssignment(token, self.getCurrentScope())
        elif token.isRuleSet():
            self.compileRuleSet(token)
            self.popScope()
        elif token.isAtRule() and token.getKeyWord() == "extend":
            self.processExtend(token)
Example #3
0
 def tokensToValue(self, tokens, scope):
     if not tokens or len(tokens) == 0:
         return None
     expression = SCSSExpression(tokens)
     expression.evaluate(scope)
     if not expression.tokens or len(expression.tokens) == 0:
         raise SCSSCompileError("Expression, expression, why did you eat my tokens?", tokens[0])
     elif len(expression.tokens) == 1:
         return scssvariables.SCSSVariable.fromToken(expression.tokens[0])
     else:
         return scssvariables.SCSSList.fromTokens(expression.tokens)
Example #4
0
 def evaluate(self, callerScope, arguments = None):
     try:
         scope = self.scope.clone()
         if arguments:
             self.mapArguments(arguments, callerScope, scope)
 
         for token in self.body:
             if token.isAssignment():
                 SCSSExpression.processAssignment(token, scope)
             elif token.isAtRule() and token.getKeyWord() == "return":
                 expression = SCSSExpression(token.getSignature())
                 expression.evaluate(scope)
                 if len(expression.tokens) == 0:
                     raise SCSSRunTimeError("Could not evaluate return statement of function %s" % self.name)
                 elif len(expression.tokens) == 1:
                     return scssvariables.SCSSVariable.fromToken(expression.tokens[0])
                 else:
                     return scssvariables.SCSSList.fromTokens(expression.tokens)
             else:
                 raise SCSSRunTimeError("Unexpected token in function %s" % self.name, token)
 
         raise SCSSRunTimeError("Function %s does not return a value" % self.name)
     except Exception, exception:
         raise SCSSRunTimeError(str(exception) + "\n  In call to function " + self.name)
Example #5
0
 def compileAny(self, token):
     if ((token.isString() or token.isIdentifier()) and
         token.data.find("#{") > -1):
         token.replaceWith(SCSSExpression.processInterpolation(token, self.getCurrentScope()))
Example #6
0
 def compileValue(self, token):
     expression = SCSSExpression.fromToken(token)
     tokens = expression.evaluate(self.getCurrentScope())
     if tokens:
         token.setChildren(tokens)
Example #7
0
 def compileAny(self, token):
     if ((token.isString() or token.isIdentifier())
             and token.data.find("#{") > -1):
         token.replaceWith(
             SCSSExpression.processInterpolation(token,
                                                 self.getCurrentScope()))
Example #8
0
 def compileValue(self, token):
     expression = SCSSExpression.fromToken(token)
     tokens = expression.evaluate(self.getCurrentScope())
     if tokens:
         token.setChildren(tokens)