SassyLists 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Changelog
2
2
 
3
+ * `0.3.0`: adding `contains()`, `flatten()`, `union()`
3
4
  * `0.2.4`: improving `debug()`
4
5
  * `0.2.3`: fixing important issues with comments
5
6
  * `0.2.2`: moving all comments to invisible
data/lib/SassyLists.rb CHANGED
@@ -5,8 +5,8 @@ Compass::Frameworks.register('SassyLists', :path => extension_path)
5
5
  # Version is a number. If a version contains alphas, it will be created as a prerelease version
6
6
  # Date is in the form of YYYY-MM-DD
7
7
  module SassyLists
8
- VERSION = "0.2.4"
9
- DATE = "2013-11-01"
8
+ VERSION = "0.3.0"
9
+ DATE = "2013-11-04"
10
10
  end
11
11
 
12
12
  module Sass::Script::Functions
@@ -11,22 +11,22 @@
11
11
  // @return [List]
12
12
 
13
13
  @function chunk($list, $size) {
14
- $n-lists: ceil(length($list) / $size);
15
- $tmp-index: 0;
16
- $result: ();
14
+ $n-lists: ceil(length($list) / $size);
15
+ $tmp-index: 0;
16
+ $result: ();
17
17
 
18
- @for $i from 1 through $n-lists {
19
- $tmp-list: ();
18
+ @for $i from 1 through $n-lists {
19
+ $tmp-list: ();
20
20
 
21
- @for $j from 1 + $tmp-index through $size + $tmp-index {
22
- @if $j <= length($list) {
23
- $tmp-list: append($tmp-list, nth($list, $j));
24
- }
25
- }
21
+ @for $j from 1 + $tmp-index through $size + $tmp-index {
22
+ @if $j <= length($list) {
23
+ $tmp-list: append($tmp-list, nth($list, $j));
24
+ }
25
+ }
26
26
 
27
- $result: append($result, $tmp-list);
28
- $tmp-index: $tmp-index + $size;
29
- }
27
+ $result: append($result, $tmp-list);
28
+ $tmp-index: $tmp-index + $size;
29
+ }
30
30
 
31
- @return $result;
31
+ @return $result;
32
32
  }
@@ -0,0 +1,15 @@
1
+ // Returns whether $list contains $value
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#contains
4
+ // -------------------------------------------------------------------------------
5
+ // @example chunk(a b c, a) => true
6
+ // @example chunk(a b c, z) => false
7
+ // -------------------------------------------------------------------------------
8
+ // @param $list [List] : list
9
+ // @param $value [Literal] : value to look for
10
+ // -------------------------------------------------------------------------------
11
+ // @return [Boolean]
12
+
13
+ @function contains($list, $value) {
14
+ @return not not index($list, $value)
15
+ }
@@ -12,22 +12,22 @@
12
12
  // @return [List]
13
13
 
14
14
  @function count-values($list) {
15
- $keys : ();
16
- $counts : ();
15
+ $keys : ();
16
+ $counts : ();
17
17
 
18
- @each $item in $list {
19
- $index: index($keys, $item);
18
+ @each $item in $list {
19
+ $index: index($keys, $item);
20
20
 
21
- @if not $index {
22
- $keys : append($keys, $item);
23
- $counts : append($counts, 1);
24
- }
21
+ @if not $index {
22
+ $keys : append($keys, $item);
23
+ $counts : append($counts, 1);
24
+ }
25
25
 
26
- @else {
27
- $count : nth($counts, $index) + 1;
28
- $counts : replace-nth($counts, $index, $count);
26
+ @else {
27
+ $count : nth($counts, $index) + 1;
28
+ $counts : replace-nth($counts, $index, $count);
29
+ }
29
30
  }
30
- }
31
31
 
32
- @return zip($keys, $counts);
32
+ @return zip($keys, $counts);
33
33
  }
@@ -9,5 +9,5 @@
9
9
  // @return [Literal]
10
10
 
11
11
  @function first($list) {
12
- @return nth($list, 1);
12
+ @return nth($list, 1);
13
13
  }
@@ -0,0 +1,27 @@
1
+ // Turns multidimensional $list into a one-level list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation.html#flatten
4
+ // -------------------------------------------------------------------------------
5
+ // @example flatten(a b (c d (e f))) => a b c d e f
6
+ // -------------------------------------------------------------------------------
7
+ // @param $list [List] : list
8
+ // -------------------------------------------------------------------------------
9
+ // @return [List]
10
+
11
+ @function flatten($list) {
12
+ $result: ();
13
+
14
+ @each $item in $list {
15
+ @if length($item) > 1 {
16
+ @each $i in flatten($item) {
17
+ $result: append($result, $i);
18
+ }
19
+ }
20
+
21
+ @else {
22
+ $result: append($result, $item);
23
+ }
24
+ }
25
+
26
+ @return $result;
27
+ }
@@ -20,34 +20,34 @@
20
20
  // @return [List] | false
21
21
 
22
22
  @function insert-nth($list, $index, $value) {
23
- $result: false;
24
-
25
- @if type-of($index) != number {
26
- @warn "List index #{quote($index)} is not a number for `insert-nth`.";
27
- @return $result;
28
- }
29
-
30
- @else if $index < 1 {
31
- @warn "List index #{quote($index)} must be a non-zero integer for `insert-nth`";
32
- @return $result;
33
- }
34
-
35
- @else if $index > length($list) {
36
- @warn "List index is #{quote($index)} but list is only #{length($list)} items long for `insert-nth'.";
37
- @return $result;
38
- }
39
-
40
- @else {
41
- $result: ();
42
-
43
- @for $i from 1 through length($list) {
44
- @if $i == $index {
45
- $result: append($result, $value);
46
- }
47
-
48
- $result: append($result, nth($list, $i));
23
+ $result: false;
24
+
25
+ @if type-of($index) != number {
26
+ @warn "List index #{quote($index)} is not a number for `insert-nth`.";
27
+ @return $result;
28
+ }
29
+
30
+ @else if $index < 1 {
31
+ @warn "List index #{quote($index)} must be a non-zero integer for `insert-nth`";
32
+ @return $result;
33
+ }
34
+
35
+ @else if $index > length($list) {
36
+ @warn "List index is #{quote($index)} but list is only #{length($list)} items long for `insert-nth'.";
37
+ @return $result;
38
+ }
39
+
40
+ @else {
41
+ $result: ();
42
+
43
+ @for $i from 1 through length($list) {
44
+ @if $i == $index {
45
+ $result: append($result, $value);
46
+ }
47
+
48
+ $result: append($result, nth($list, $i));
49
+ }
49
50
  }
50
- }
51
51
 
52
- @return purge($result);
52
+ @return purge($result);
53
53
  }
@@ -13,5 +13,5 @@
13
13
  // @return [Boolean]
14
14
 
15
15
  @function is-symmetrical($list) {
16
- @return reverse($list) == reverse(reverse($list));
16
+ @return reverse($list) == reverse(reverse($list));
17
17
  }
@@ -12,14 +12,11 @@
12
12
 
13
13
  @function last-index($list, $value) {
14
14
 
15
- @for $i from length($list) * -1 through -1 {
16
- $i: abs($i);
17
-
18
- @if nth($list, $i) == $value {
19
- @return $i;
20
- }
21
-
22
- }
15
+ @for $i from length($list) * -1 through -1 {
16
+ @if nth($list, abs($i)) == $value {
17
+ @return abs($i);
18
+ }
19
+ }
23
20
 
24
21
  @return null;
25
22
  }
@@ -9,5 +9,5 @@
9
9
  // @return [Literal]
10
10
 
11
11
  @function last($list) {
12
- @return nth($list, length($list));
12
+ @return nth($list, length($list));
13
13
  }
@@ -12,11 +12,11 @@
12
12
  // @return [List]
13
13
 
14
14
  @function loop($list, $value: 1) {
15
- $result: ();
16
-
17
- @for $i from 0 to length($list) {
18
- $result: append($result, nth($list, ($i - $value) % length($list) + 1));
19
- }
20
-
21
- @return $result;
15
+ $result: ();
16
+
17
+ @for $i from 0 to length($list) {
18
+ $result: append($result, nth($list, ($i - $value) % length($list) + 1));
19
+ }
20
+
21
+ @return $result;
22
22
  }
@@ -13,5 +13,5 @@
13
13
  // @return [List]
14
14
 
15
15
  @function prepend($list, $value) {
16
- @return purge(join($value, $list));
16
+ @return purge(join($value, $list));
17
17
  }
@@ -10,13 +10,13 @@
10
10
  // @return [List]
11
11
 
12
12
  @function purge($list) {
13
- $result: ();
14
-
15
- @each $item in $list {
16
- @if $item != null and $item != false and $item != "" {
17
- $result: append($result, $item);
18
- }
19
- }
20
-
21
- @return $result;
13
+ $result: ();
14
+
15
+ @each $item in $list {
16
+ @if $item != null and $item != false and $item != "" {
17
+ $result: append($result, $item);
18
+ }
19
+ }
20
+
21
+ @return $result;
22
22
  }
@@ -11,5 +11,5 @@
11
11
  // @return [Literal]
12
12
 
13
13
  @function random-value($list) {
14
- @return nth($list, random(length($list)) + 1);
14
+ @return nth($list, random(length($list)) + 1);
15
15
  }
@@ -11,21 +11,19 @@
11
11
  // @return [List]
12
12
 
13
13
  @function remove-duplicates($list, $recursive: false) {
14
- $result: ();
15
-
16
- @each $item in $list {
14
+ $result: ();
17
15
 
18
- @if not index($result, $item) {
19
- @if length($item) > 1 and $recursive {
20
- $result: append($result, remove-duplicates($item, $recursive));
21
- }
22
-
23
- @else {
24
- $result: append($result, $item);
25
- }
16
+ @each $item in $list {
17
+ @if not index($result, $item) {
18
+ @if length($item) > 1 and $recursive {
19
+ $result: append($result, remove-duplicates($item, $recursive));
20
+ }
21
+
22
+ @else {
23
+ $result: append($result, $item);
24
+ }
25
+ }
26
26
  }
27
27
 
28
- }
29
-
30
- @return $result;
28
+ @return $result;
31
29
  }
@@ -20,5 +20,5 @@
20
20
  // @return [List] | false
21
21
 
22
22
  @function remove-nth($list, $index) {
23
- @return replace-nth($list, $index, "");
23
+ @return replace-nth($list, $index, "");
24
24
  }
@@ -16,5 +16,5 @@
16
16
  // @return [List]
17
17
 
18
18
  @function remove($list, $value, $recursive: false) {
19
- @return replace($list, $value, "", $recursive);
19
+ @return replace($list, $value, "", $recursive);
20
20
  }
@@ -21,31 +21,31 @@
21
21
  // @return [List] | false
22
22
 
23
23
  @function replace-nth($list, $index, $value) {
24
- $result: false;
25
-
26
- @if type-of($index) != number {
27
- @warn "List index #{quote($index)} is not a number for `replace-nth`/`remove-nth`.";
28
- @return $result;
29
- }
24
+ $result: false;
30
25
 
31
- @else if $index == 0 {
32
- @warn "List index 0 must be a non-zero integer for `replace-nth`/`remove-nth`.";
33
- @return $result;
34
- }
35
-
36
- @else if abs($index) > length($list) {
37
- @warn "List index is #{quote($index)} but list is only #{length($list)} item long for `replace-nth`/`remove-nth`.";
38
- @return $result;
39
- }
26
+ @if type-of($index) != number {
27
+ @warn "List index #{quote($index)} is not a number for `replace-nth`/`remove-nth`.";
28
+ @return $result;
29
+ }
30
+
31
+ @else if $index == 0 {
32
+ @warn "List index 0 must be a non-zero integer for `replace-nth`/`remove-nth`.";
33
+ @return $result;
34
+ }
40
35
 
41
- @else {
42
- $result: ();
43
- $index: if($index < 0, length($list) + $index + 1, $index);
36
+ @else if abs($index) > length($list) {
37
+ @warn "List index is #{quote($index)} but list is only #{length($list)} item long for `replace-nth`/`remove-nth`.";
38
+ @return $result;
39
+ }
40
+
41
+ @else {
42
+ $result: ();
43
+ $index: if($index < 0, length($list) + $index + 1, $index);
44
44
 
45
- @for $i from 1 through length($list) {
46
- $result: append($result, if($i == $index, $value, nth($list, $i)));
45
+ @for $i from 1 through length($list) {
46
+ $result: append($result, if($i == $index, $value, nth($list, $i)));
47
+ }
47
48
  }
48
- }
49
-
50
- @return purge($result);
49
+
50
+ @return purge($result);
51
51
  }
@@ -17,17 +17,17 @@
17
17
  // @return [List]
18
18
 
19
19
  @function replace($list, $old-value, $new-value, $recursive: false) {
20
- $result: ();
20
+ $result: ();
21
21
 
22
- @each $item in $list {
23
- @if length($item) > 1 and $recursive {
24
- $result: append($result, replace($item, $old-value, $new-value, $recursive));
25
- }
22
+ @each $item in $list {
23
+ @if length($item) > 1 and $recursive {
24
+ $result: append($result, replace($item, $old-value, $new-value, $recursive));
25
+ }
26
26
 
27
- @else {
28
- $result: append($result, if($item == $old-value, $new-value, $item));
27
+ @else {
28
+ $result: append($result, if($item == $old-value, $new-value, $item));
29
+ }
29
30
  }
30
- }
31
31
 
32
- @return purge($result);
32
+ @return purge($result);
33
33
  }
@@ -12,19 +12,19 @@
12
12
  // @return [List]
13
13
 
14
14
  @function reverse($list, $recursive: false) {
15
- $result: ();
15
+ $result: ();
16
16
 
17
- @for $i from length($list) * -1 through -1 {
18
- $item: nth($list, abs($i));
17
+ @for $i from length($list) * -1 through -1 {
18
+ $item: nth($list, abs($i));
19
19
 
20
- @if length($item) > 1 and $recursive {
21
- $result: append($result, reverse($item, $recursive));
22
- }
20
+ @if length($item) > 1 and $recursive {
21
+ $result: append($result, reverse($item, $recursive));
22
+ }
23
23
 
24
- @else {
25
- $result: append($result, $item);
24
+ @else {
25
+ $result: append($result, $item);
26
+ }
26
27
  }
27
- }
28
28
 
29
- @return $result;
29
+ @return $result;
30
30
  }
@@ -22,40 +22,40 @@
22
22
  // @return [List] | false
23
23
 
24
24
  @function slice($list, $start: 1, $end: length($list)) {
25
- $result: false;
26
-
27
- @if type-of($start) != number or type-of($end) != number {
28
- @warn "List indexes #{quote($start)} and #{quote($end)} must be numbers for `slice`.";
29
- @return $result;
30
- }
31
-
32
- @else if $start > $end {
33
- @warn "Start index is #{quote($start)} but has to be lesser than or equals to the end index (#{quote($end)}) for `slice`.";
34
- @return $result;
35
- }
25
+ $result: false;
26
+
27
+ @if type-of($start) != number or type-of($end) != number {
28
+ @warn "List indexes #{quote($start)} and #{quote($end)} must be numbers for `slice`.";
29
+ @return $result;
30
+ }
31
+
32
+ @else if $start > $end {
33
+ @warn "Start index is #{quote($start)} but has to be lesser than or equals to the end index (#{quote($end)}) for `slice`.";
34
+ @return $result;
35
+ }
36
36
 
37
- @else if $start < 1 or $end < 1 {
38
- @warn "List indexes must be non-zero integers for `slice`.";
39
- @return $result;
40
- }
37
+ @else if $start < 1 or $end < 1 {
38
+ @warn "List indexes must be non-zero integers for `slice`.";
39
+ @return $result;
40
+ }
41
41
 
42
- @else if $start > length($list) {
43
- @warn "Start index is #{quote($start)} but list is only #{length($list)} items long for `slice`.";
44
- @return $result;
45
- }
46
-
47
- @else if $end > length($list) {
48
- @warn "End index is #{quote($end)} but list is only #{length($list)} items long for `slice`.";
49
- @return $result;
50
- }
51
-
52
- @else {
53
- $result: ();
54
-
55
- @for $i from $start through $end {
56
- $result: append($result, nth($list, $i));
42
+ @else if $start > length($list) {
43
+ @warn "Start index is #{quote($start)} but list is only #{length($list)} items long for `slice`.";
44
+ @return $result;
45
+ }
46
+
47
+ @else if $end > length($list) {
48
+ @warn "End index is #{quote($end)} but list is only #{length($list)} items long for `slice`.";
49
+ @return $result;
57
50
  }
58
- }
59
51
 
60
- @return $result;
52
+ @else {
53
+ $result: ();
54
+
55
+ @for $i from $start through $end {
56
+ $result: append($result, nth($list, $i));
57
+ }
58
+ }
59
+
60
+ @return $result;
61
61
  }
@@ -15,48 +15,48 @@
15
15
  // @return [List]
16
16
 
17
17
  @function sort($list, $force: false) {
18
- $result : nth($list, 1);
19
-
20
- @if length($list) > 1 {
18
+ $result : nth($list, 1);
21
19
 
22
- @for $i from 2 through length($list) {
23
- $item: nth($list, $i);
20
+ @if length($list) > 1 {
24
21
 
25
- @if type-of($item) == number {
22
+ @for $i from 2 through length($list) {
23
+ $item: nth($list, $i);
26
24
 
27
- @if unitless($item) and $force {
25
+ @if type-of($item) == number {
28
26
 
29
- @if $item > last($result) {
30
- $result: append($result, $item);
31
- }
27
+ @if unitless($item) and $force {
32
28
 
33
- @else {
34
- $index: 0;
29
+ @if $item > last($result) {
30
+ $result: append($result, $item);
31
+ }
35
32
 
36
- @for $i from length($result) * -1 through -1 {
37
- $i: abs($i);
38
-
39
- @if $item <= nth($result, $i) {
40
- $index: $i;
41
- }
42
- }
33
+ @else {
34
+ $index: 0;
43
35
 
44
- $result: insert-nth($result, $index, $item);
45
- }
36
+ @for $i from length($result) * -1 through -1 {
37
+ $i: abs($i);
46
38
 
47
- }
39
+ @if $item <= nth($result, $i) {
40
+ $index: $i;
41
+ }
42
+ }
43
+
44
+ $result: insert-nth($result, $index, $item);
45
+ }
48
46
 
49
- @else {
50
- @warn "Not unitless number found. Omitted.";
51
- }
47
+ }
48
+
49
+ @else {
50
+ @warn "Not unitless number found. Omitted.";
51
+ }
52
52
 
53
- }
53
+ }
54
54
 
55
- @else {
56
- @warn "Not integer value found. Omitted.";
57
- }
55
+ @else {
56
+ @warn "Not integer value found. Omitted.";
57
+ }
58
+ }
58
59
  }
59
- }
60
-
61
- @return $result;
60
+
61
+ @return $result;
62
62
  }
@@ -13,21 +13,21 @@
13
13
  // @return [Number]
14
14
 
15
15
  @function sum($list, $force: false) {
16
- $result: 0;
17
-
18
- @each $item in $list {
19
- @if type-of($item) == number {
16
+ $result: 0;
20
17
 
21
- @if $force and unit($item) {
22
- $item: $item / ($item * 0 + 1);
23
- }
18
+ @each $item in $list {
19
+ @if type-of($item) == number {
24
20
 
25
- @if unitless($item) {
26
- $result: $result + $item;
27
- }
28
-
21
+ @if $force and unit($item) {
22
+ $item: $item / ($item * 0 + 1);
23
+ }
24
+
25
+ @if unitless($item) {
26
+ $result: $result + $item;
27
+ }
28
+
29
+ }
29
30
  }
30
- }
31
-
32
- @return $result;
31
+
32
+ @return $result;
33
33
  }
@@ -13,18 +13,18 @@
13
13
  // @return [String]
14
14
 
15
15
  @function to-string($list, $glue: '', $root: true) {
16
- $result: null;
16
+ $result: null;
17
17
 
18
- @each $item in $list {
19
- @if length($item) > 1 {
20
- $result: $result#{to-string($item, $glue, false)};
21
- }
18
+ @each $item in $list {
19
+ @if length($item) > 1 {
20
+ $result: $result#{to-string($item, $glue, false)};
21
+ }
22
22
 
23
- @else {
24
- $condition: index($list, $item) != length($list) or not $root;
25
- $result: if($condition, $result#{$item}#{$glue}, $result#{$item});
23
+ @else {
24
+ $condition: index($list, $item) != length($list) or not $root;
25
+ $result: if($condition, $result#{$item}#{$glue}, $result#{$item});
26
+ }
26
27
  }
27
- }
28
28
 
29
- @return quote($result);
29
+ @return quote($result);
30
30
  }
@@ -0,0 +1,16 @@
1
+ // Returns a list of shared values from $lists
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#union
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `flatten()`
6
+ // @dependence `remove-duplicates()`
7
+ // -------------------------------------------------------------------------------
8
+ // @example union((a b), (b c), (a b c d)) => a b c d
9
+ // -------------------------------------------------------------------------------
10
+ // @param $lists [ArgList] : lists
11
+ // -------------------------------------------------------------------------------
12
+ // @return [List]
13
+
14
+ @function union($lists...) {
15
+ @return remove-duplicates(flatten($lists));
16
+ }
@@ -7,9 +7,11 @@
7
7
  // -------------------------------------------------------------------------------
8
8
 
9
9
  @import "SassyLists/chunk";
10
+ @import "SassyLists/contains";
10
11
  @import "SassyLists/count-values";
11
12
  @import "SassyLists/debug";
12
13
  @import "SassyLists/first";
14
+ @import "SassyLists/flatten";
13
15
  @import "SassyLists/insert-nth";
14
16
  @import "SassyLists/is-symmetrical";
15
17
  @import "SassyLists/last";
@@ -27,4 +29,5 @@
27
29
  @import "SassyLists/slice";
28
30
  @import "SassyLists/sort";
29
31
  @import "SassyLists/sum";
30
- @import "SassyLists/to-string";
32
+ @import "SassyLists/to-string";
33
+ @import "SassyLists/union";
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SassyLists
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-01 00:00:00.000000000 Z
12
+ date: 2013-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sass
@@ -53,9 +53,11 @@ files:
53
53
  - CHANGELOG.md
54
54
  - lib/SassyLists.rb
55
55
  - stylesheets/SassyLists/_chunk.scss
56
+ - stylesheets/SassyLists/_contains.scss
56
57
  - stylesheets/SassyLists/_count-values.scss
57
58
  - stylesheets/SassyLists/_debug.scss
58
59
  - stylesheets/SassyLists/_first.scss
60
+ - stylesheets/SassyLists/_flatten.scss
59
61
  - stylesheets/SassyLists/_insert-nth.scss
60
62
  - stylesheets/SassyLists/_is-symmetrical.scss
61
63
  - stylesheets/SassyLists/_last-index.scss
@@ -74,6 +76,7 @@ files:
74
76
  - stylesheets/SassyLists/_sort.scss
75
77
  - stylesheets/SassyLists/_sum.scss
76
78
  - stylesheets/SassyLists/_to-string.scss
79
+ - stylesheets/SassyLists/_union.scss
77
80
  - stylesheets/_SassyLists.scss
78
81
  homepage: http://sassylists.com/
79
82
  licenses: []