Example #1
0
def parse_bareword(word):
    if word in COLOR_NAMES:
        return Color.from_name(word)
    elif word == 'null':
        return Null()
    elif word == 'undefined':
        return Undefined()
    elif word == 'true':
        return Boolean(True)
    elif word == 'false':
        return Boolean(False)
    else:
        return String(word, quotes=None)
Example #2
0
    def from_bareword(cls, word):
        if word in COLOR_NAMES:
            value = Color.from_name(word)
        elif word == 'null':
            value = Null()
        elif word == 'undefined':
            value = Undefined()
        elif word == 'true':
            value = Boolean(True)
        elif word == 'false':
            value = Boolean(False)
        else:
            value = String(word, quotes=None)

        return cls(value)
Example #3
0
 def evaluate(self, calculator, divide=False):
     try:
         value = calculator.namespace.variable(self.name)
     except KeyError:
         if FATAL_UNDEFINED:
             raise
         else:
             log.error("Undefined variable '%s'",
                       self.name,
                       extra={'stack': True})
             return Undefined()
     else:
         if isinstance(value, six.string_types):
             evald = calculator.evaluate_expression(value)
             if evald is not None:
                 return evald
         return value
Example #4
0
 def evaluate(self, calculator, divide=False):
     try:
         value = calculator.namespace.variable(self.name)
     except KeyError:
         if calculator.undefined_variables_fatal:
             raise SyntaxError("Undefined variable: '%s'." % self.name)
         else:
             log.error("Undefined variable '%s'", self.name, extra={'stack': True})
             return Undefined()
     else:
         if isinstance(value, six.string_types):
             log.warn(
                 "Expected a Sass type for the value of {0}, "
                 "but found a string expression: {1!r}"
                 .format(self.name, value)
             )
             evald = calculator.evaluate_expression(value)
             if evald is not None:
                 return evald
         return value