summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <eevee.git@veekun.com>2013-08-21 19:19:51 -0700
committerEevee (Alex Munroe) <eevee.git@veekun.com>2013-08-21 19:19:51 -0700
commit1e163eb41638ce3bc93f40b45ca47ec2f0b647b2 (patch)
tree7ae246afd0faa7c8c02aae20b2c7aa49af8a97c5
parent5a3d657e6c04551f28e4d8171343cf29288f5282 (diff)
downloadpyscss-1e163eb41638ce3bc93f40b45ca47ec2f0b647b2.tar.gz
Avoid using Number.unit in gradient math.
-rw-r--r--scss/functions/compass/gradients.py6
-rw-r--r--scss/types.py13
2 files changed, 16 insertions, 3 deletions
diff --git a/scss/functions/compass/gradients.py b/scss/functions/compass/gradients.py
index 37fd5fe..5f4d60d 100644
--- a/scss/functions/compass/gradients.py
+++ b/scss/functions/compass/gradients.py
@@ -62,13 +62,13 @@ def __color_stops(percentages, *args):
if stops[-1] is None:
stops[-1] = Number(100, '%')
- maxable_stops = [s for s in stops if s and s.unit != '%']
+ maxable_stops = [s for s in stops if s and not s.is_simple_unit('%')]
if maxable_stops:
max_stops = max(maxable_stops)
else:
max_stops = None
- stops = [_s / max_stops if _s and _s.unit != '%' else _s for _s in stops]
+ stops = [_s / max_stops if _s and not _s.is_simple_unit('%') else _s for _s in stops]
init = 0
start = None
@@ -89,7 +89,7 @@ def __color_stops(percentages, *args):
if not max_stops or percentages:
pass
else:
- stops = [s if s.unit == '%' else s * max_stops for s in stops]
+ stops = [s if s.is_simple_unit('%') else s * max_stops for s in stops]
return zip(stops, colors)
diff --git a/scss/types.py b/scss/types.py
index 320dc38..01335c5 100644
--- a/scss/types.py
+++ b/scss/types.py
@@ -471,6 +471,19 @@ class Number(Value):
"""
return len(self.unit_numer) <= 1 and not self.unit_denom
+ def is_simple_unit(self, unit):
+ """Return True iff the unit is simple (as above) and matches the given
+ unit.
+ """
+ if self.unit_denom or len(self.unit_numer) > 1:
+ return False
+
+ if not self.unit_numer:
+ # Empty string historically means no unit
+ return unit == ''
+
+ return self.unit_numer[0] == unit
+
@property
def is_unitless(self):
return not self.unit_numer and not self.unit_denom