diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-08-22 14:08:03 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-08-22 14:08:03 -0700 |
commit | 8b163b84c3d3c7aaee881d63005c85f23a96f205 (patch) | |
tree | 2734a64c45239b5cd81351079ab269ef728791ea | |
parent | 1e163eb41638ce3bc93f40b45ca47ec2f0b647b2 (diff) | |
download | pyscss-8b163b84c3d3c7aaee881d63005c85f23a96f205.tar.gz |
Remove Number.unit.
-rw-r--r-- | scss/functions/compass/gradients.py | 2 | ||||
-rw-r--r-- | scss/functions/compass/helpers.py | 4 | ||||
-rw-r--r-- | scss/functions/compass/sprites.py | 12 | ||||
-rw-r--r-- | scss/functions/core.py | 2 | ||||
-rw-r--r-- | scss/types.py | 18 |
5 files changed, 14 insertions, 24 deletions
diff --git a/scss/functions/compass/gradients.py b/scss/functions/compass/gradients.py index 5f4d60d..6387dec 100644 --- a/scss/functions/compass/gradients.py +++ b/scss/functions/compass/gradients.py @@ -138,7 +138,7 @@ def grad_point(*p): def __grad_position(index, default, radial, color_stops): try: stops = Number(color_stops[index][0]) - if radial and stops.unit != 'px' and (index == 0 or index == -1 or index == len(color_stops) - 1): + if radial and not stops.is_simple_unit('px') and (index == 0 or index == -1 or index == len(color_stops) - 1): log.warn("Webkit only supports pixels for the start and end stops for radial gradients. Got %s", stops) except IndexError: stops = Number(default) diff --git a/scss/functions/compass/helpers.py b/scss/functions/compass/helpers.py index c1de01f..72df2e7 100644 --- a/scss/functions/compass/helpers.py +++ b/scss/functions/compass/helpers.py @@ -404,13 +404,13 @@ def _position(opposite, positions): continue elif isinstance(pos, Number): - if pos.unit == '%': + if pos.is_simple_unit('%'): if opposite: ret.append(Number(100 - pos.value, '%')) else: ret.append(pos) continue - elif pos.unit == 'deg': + elif pos.is_simple_unit('deg'): # TODO support other angle types? if opposite: ret.append(Number((pos.value + 180) % 360, 'deg')) diff --git a/scss/functions/compass/sprites.py b/scss/functions/compass/sprites.py index 637a0de..ebde363 100644 --- a/scss/functions/compass/sprites.py +++ b/scss/functions/compass/sprites.py @@ -197,7 +197,7 @@ def sprite_map(g, **kwargs): collapse_y = int(Number(kwargs['collapse_y']).value) position = Number(kwargs.get('position', 0)) - if position.unit != '%' and position.value > 1: + if not position.is_simple_unit('%') and position.value > 1: position = position.value / 100.0 else: position = position.value @@ -243,7 +243,7 @@ def sprite_map(g, **kwargs): _position = position else: _position = Number(_position) - if _position.unit != '%' and _position.value > 1: + if not _position.is_simple_unit('%') and _position.value > 1: _position = _position.value / 100.0 else: _position = _position.value @@ -455,9 +455,9 @@ def sprite(map, sprite, offset_x=None, offset_y=None, cache_buster=True): url += '?_=%s' % sprite_map['*t*'] x = Number(offset_x or 0, 'px') y = Number(offset_y or 0, 'px') - if not x.value or (x.value <= -1 or x.value >= 1) and x.unit != '%': + if not x.value or (x.value <= -1 or x.value >= 1) and not x.is_simple_unit('%'): x -= Number(sprite[2], 'px') - if not y.value or (y.value <= -1 or y.value >= 1) and y.unit != '%': + if not y.value or (y.value <= -1 or y.value >= 1) and not y.is_simple_unit('%'): y -= Number(sprite[3], 'px') url = "url(%s)" % escape(url) return List([String.unquoted(url), x, y]) @@ -507,7 +507,7 @@ def sprite_position(map, sprite, offset_x=None, offset_y=None): if x: offset_x = None x = Number(offset_x or 0, 'px') - if not x.value or (x.value <= -1 or x.value >= 1) and x.unit != '%': + if not x.value or (x.value <= -1 or x.value >= 1) and not x.is_simple_unit('%'): x -= Number(sprite[2], 'px') y = None if offset_y is not None and not isinstance(offset_y, Number): @@ -516,7 +516,7 @@ def sprite_position(map, sprite, offset_x=None, offset_y=None): if y: offset_y = None y = Number(offset_y or 0, 'px') - if not y.value or (y.value <= -1 or y.value >= 1) and y.unit != '%': + if not y.value or (y.value <= -1 or y.value >= 1) and not y.is_simple_unit('%'): y -= Number(sprite[3], 'px') return List([x, y]) return List([Number(0), Number(0)]) diff --git a/scss/functions/core.py b/scss/functions/core.py index 402e581..488c528 100644 --- a/scss/functions/core.py +++ b/scss/functions/core.py @@ -44,7 +44,7 @@ def _apply_percentage(n, relto=1): if n.is_unitless: return n.value - elif n.unit == '%': + elif n.is_simple_unit('%'): return n.value * relto / 100. else: raise TypeError("Expected unitless number or percentage, got %r" % (n,)) diff --git a/scss/types.py b/scss/types.py index 01335c5..1a8c654 100644 --- a/scss/types.py +++ b/scss/types.py @@ -452,19 +452,6 @@ class Number(Value): return wrapped @property - def unit(self): - if self.unit_denom: - raise TypeError - - if not self.unit_numer: - return '' - - if len(self.unit_numer) != 1: - raise TypeError - - return self.unit_numer[0] - - @property def has_simple_unit(self): """Returns True iff the unit is expressible in CSS, i.e., has no denominator and at most one unit in the numerator. @@ -492,7 +479,10 @@ class Number(Value): if not self.has_simple_unit: raise ValueError("Can't express compound units in CSS: %r" % (self,)) - unit = self.unit + if self.unit_numer: + unit = self.unit_numer[0] + else: + unit = '' if compress and unit in ZEROABLE_UNITS and self.value == 0: return '0' |