diff options
author | German M. Bravo <german.mb@deipi.com> | 2013-08-13 12:02:59 -0500 |
---|---|---|
committer | German M. Bravo <german.mb@deipi.com> | 2013-08-13 12:02:59 -0500 |
commit | 791af4f6fb10f963810702021da399591445a5f4 (patch) | |
tree | b908c3cfb5f9acac5d097c63ed2874bdcc1e91a0 | |
parent | f87dcd4324d2dbbeb3943f7b191c58688c313c1b (diff) | |
download | pyscss-791af4f6fb10f963810702021da399591445a5f4.tar.gz |
Added Undefined type. Undefined variables get this value if FATAL_UNDEFINED is False
-rw-r--r-- | scss/expression.py | 9 | ||||
-rw-r--r-- | scss/rule.py | 13 | ||||
-rw-r--r-- | scss/types.py | 8 |
3 files changed, 24 insertions, 6 deletions
diff --git a/scss/expression.py b/scss/expression.py index 55a1bdd..0b03aa2 100644 --- a/scss/expression.py +++ b/scss/expression.py @@ -9,7 +9,7 @@ import six import scss.config as config from scss.cssdefs import COLOR_NAMES, is_builtin_css_function, _expr_glob_re, _interpolate_re, _variable_re -from scss.types import BooleanValue, ColorValue, ListValue, Null, NumberValue, ParserValue, String +from scss.types import BooleanValue, ColorValue, ListValue, Null, Undefined, NumberValue, ParserValue, String from scss.util import dequote, normalize_var, to_str ################################################################################ @@ -292,7 +292,8 @@ class CallOp(Expression): u"%s(%s)" % (self.func_name, u", ".join(rendered_args)), quotes=None) else: - return func(*args, **kwargs) + if func is not None and not func.is_null: + return func(*args, **kwargs) class Literal(Expression): def __init__(self, value): @@ -337,8 +338,10 @@ class ArgspecLiteral(Expression): def parse_bareword(word): if word in COLOR_NAMES: return ColorValue.from_name(word) - elif word in ('null', 'undefined'): + elif word == 'null': return Null() + elif word == 'undefined': + return Undefined() elif word == 'true': return BooleanValue(True) elif word == 'false': diff --git a/scss/rule.py b/scss/rule.py index 5b7cbfc..ff445a7 100644 --- a/scss/rule.py +++ b/scss/rule.py @@ -2,8 +2,15 @@ from __future__ import absolute_import from __future__ import print_function import six +import logging from scss.cssdefs import _has_placeholder_re +from scss.types import Undefined + +log = logging.getLogger(__name__) + + +FATAL_UNDEFINED = False def normalize_var(name): @@ -29,7 +36,11 @@ class VariableScope(object): if key in map: return map[key] - raise KeyError(key) + if FATAL_UNDEFINED: + raise KeyError(key) + + log.error("Undefined variable '%s'", key) + return Undefined() def __setitem__(self, key, value): for map in self.maps: diff --git a/scss/types.py b/scss/types.py index 303e01c..1e314eb 100644 --- a/scss/types.py +++ b/scss/types.py @@ -99,7 +99,7 @@ class Null(Value): pass def __str__(self): - return 'null' + return self.sass_type_name def __repr__(self): return "<%s>" % (type(self).__name__,) @@ -114,7 +114,11 @@ class Null(Value): return isinstance(other, Null) def render(self, compress=False): - return 'null' + return self.sass_type_name + + +class Undefined(Null): + sass_type_name = u'undefined' class BooleanValue(Value): |