summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerman M. Bravo <german.mb@deipi.com>2013-10-07 09:11:51 -0500
committerGerman M. Bravo <german.mb@deipi.com>2013-10-07 09:23:26 -0500
commit9e60429b49797aa0cff4f95a6251f18e9e03dede (patch)
tree901b5615a7969c844d1ebff9f91f193d4edc29e6
parentec419cf96650d3b1fabd39acd057747a0ae77760 (diff)
downloadpyscss-9e60429b49797aa0cff4f95a6251f18e9e03dede.tar.gz
Lists operations are handled element-wise
-rw-r--r--scss/tests/files/kronuz/lists-addition.css3
-rw-r--r--scss/tests/files/kronuz/lists-addition.scss7
-rw-r--r--scss/tests/files/kronuz/lists-operations.css7
-rw-r--r--scss/tests/files/kronuz/lists-operations.scss9
-rw-r--r--scss/types.py19
5 files changed, 31 insertions, 14 deletions
diff --git a/scss/tests/files/kronuz/lists-addition.css b/scss/tests/files/kronuz/lists-addition.css
deleted file mode 100644
index 2a64475..0000000
--- a/scss/tests/files/kronuz/lists-addition.css
+++ /dev/null
@@ -1,3 +0,0 @@
-div {
- margin: -5px 0 0;
-}
diff --git a/scss/tests/files/kronuz/lists-addition.scss b/scss/tests/files/kronuz/lists-addition.scss
deleted file mode 100644
index 25123b4..0000000
--- a/scss/tests/files/kronuz/lists-addition.scss
+++ /dev/null
@@ -1,7 +0,0 @@
-@option style:legacy;
-
-div {
- $a: 4px 0 0;
- $b: 1px 0 0 0;
- margin: -($a + $b);
-}
diff --git a/scss/tests/files/kronuz/lists-operations.css b/scss/tests/files/kronuz/lists-operations.css
new file mode 100644
index 0000000..3337d63
--- /dev/null
+++ b/scss/tests/files/kronuz/lists-operations.css
@@ -0,0 +1,7 @@
+div {
+ margin: 8px 0 4px;
+ margin: 2px 0 1px;
+ margin: 6px 2px 4px;
+ margin: 7px 1px 7px;
+ margin: -4px 0 -2px;
+}
diff --git a/scss/tests/files/kronuz/lists-operations.scss b/scss/tests/files/kronuz/lists-operations.scss
new file mode 100644
index 0000000..d930aae
--- /dev/null
+++ b/scss/tests/files/kronuz/lists-operations.scss
@@ -0,0 +1,9 @@
+@option style:legacy;
+
+div {
+ margin: (4px 0 2px) * 2;
+ margin: (4px 0 2px) / 2;
+ margin: (4px 0 2px) + 2px;
+ margin: (4px 0 2px) + (3px 1px 5px 2px);
+ margin: -(4px 0 2px);
+}
diff --git a/scss/types.py b/scss/types.py
index 6cc58f7..f34552c 100644
--- a/scss/types.py
+++ b/scss/types.py
@@ -618,28 +618,39 @@ class List(Value):
# DEVIATION: binary ops on lists and scalars act element-wise
def __add__(self, other):
if isinstance(other, List):
- return super(List, self).__add__(other)
+ max_list, min_list = (self, other) if len(self) > len(other) else (other, self)
+ return List([item + max_list[i] for i, item in enumerate(min_list)], use_comma=self.use_comma)
return List([item + other for item in self], use_comma=self.use_comma)
def __sub__(self, other):
if isinstance(other, List):
- return super(List, self).__sub__(other)
+ max_list, min_list = (self, other) if len(self) > len(other) else (other, self)
+ return List([item - max_list[i] for i, item in enumerate(min_list)], use_comma=self.use_comma)
return List([item - other for item in self], use_comma=self.use_comma)
def __mul__(self, other):
if isinstance(other, List):
- return super(List, self).__mul__(other)
+ max_list, min_list = (self, other) if len(self) > len(other) else (other, self)
+ max_list, min_list = (self, other) if len(self) > len(other) else (other, self)
+ return List([item * max_list[i] for i, item in enumerate(min_list)], use_comma=self.use_comma)
return List([item * other for item in self], use_comma=self.use_comma)
def __div__(self, other):
if isinstance(other, List):
- return super(List, self).__div__(other)
+ max_list, min_list = (self, other) if len(self) > len(other) else (other, self)
+ return List([item / max_list[i] for i, item in enumerate(min_list)], use_comma=self.use_comma)
return List([item / other for item in self], use_comma=self.use_comma)
+ def __pos__(self):
+ return self
+
+ def __neg__(self):
+ return List([-item for item in self], use_comma=self.use_comma)
+
def _constrain(value, lb=0, ub=1):
"""Helper for Color constructors. Constrains a value to a range."""