SassyLists 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Changelog
2
2
 
3
- * `0.4.5`: made `sort()` able to return in descending order
3
+ * `0.4.6`: fixing an issue when passing an empty list to `chunk()` and improved code quality
4
+ * `0.4.5`: making `sort()` able to return in descending order
4
5
  * `0.4.4`: fixing a typo in `purge()`
5
6
  * `0.4.3`: improving `insert-nth()`, `prepend()`, `replace-nth()` and `replace()` to prevent from adding empty lists
6
7
  * `0.4.2`: improving `insert-nth()` and cleaning some indentation issues
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.4.5"
9
- DATE = "2013-12-06"
8
+ VERSION = "0.4.6"
9
+ DATE = "2013-12-07"
10
10
  end
11
11
 
12
12
  module Sass::Script::Functions
@@ -8,9 +8,16 @@
8
8
  // @param $list [List] : list
9
9
  // @param $size [Number] : length of lists
10
10
  // -------------------------------------------------------------------------------
11
- // @return [List]
11
+ // @raise [Error] if $list is empty
12
+ // -------------------------------------------------------------------------------
13
+ // @return [List] | false
12
14
 
13
15
  @function chunk($list, $size) {
16
+ @if $list == () {
17
+ @warn "Trying to chunk empty list in `chunk`.";
18
+ @return false;
19
+ }
20
+
14
21
  @if $size >= length($list) {
15
22
  @return $list;
16
23
  }
@@ -13,7 +13,7 @@
13
13
  // @return [Boolean]
14
14
 
15
15
  @function contain($list, $value) {
16
- @return not not index($list, $value)
16
+ @return not not index($list, $value);
17
17
  }
18
18
 
19
19
  // Alias
@@ -12,10 +12,6 @@
12
12
  // @return [String]
13
13
 
14
14
  @function debug($list, $pre: false, $level: 1) {
15
- $tab: " ";
16
- $indent: "";
17
- $break: if($pre, "\A ", "");
18
-
19
15
  @if length($list) == 0 {
20
16
  @return "( )";
21
17
  }
@@ -24,6 +20,10 @@
24
20
  @return if($pre, "(" + type-of($list) + ") ", "") + $list;
25
21
  }
26
22
 
23
+ $tab: " ";
24
+ $indent: "";
25
+ $break: if($pre, "\A ", "");
26
+
27
27
  @for $i from 1 to $level {
28
28
  $indent: $indent + $tab;
29
29
  }
@@ -18,34 +18,30 @@
18
18
  // @return [List] | false
19
19
 
20
20
  @function insert-nth($list, $index, $value) {
21
- $result: false;
22
-
23
21
  @if type-of($index) != number {
24
22
  @warn "List index #{$index} is not a number for `insert-nth`.";
25
- @return $result;
23
+ @return false;
26
24
  }
27
25
 
28
- @else if $index < 1 {
26
+ @if $index < 1 {
29
27
  @warn "List index #{$index} must be a non-zero integer for `insert-nth`";
30
- @return $result;
28
+ @return false;
31
29
  }
32
30
 
33
- @else if $index > length($list) {
31
+ @if $index > length($list) {
34
32
  @return append($list, $value);
35
33
  }
36
34
 
37
- @else {
38
- $result: ();
35
+ $result: ();
39
36
 
40
- @for $i from 1 through length($list) {
41
- @if $i == $index {
42
- @if $value and $value != "" and $value != () {
43
- $result: append($result, $value);
44
- }
37
+ @for $i from 1 through length($list) {
38
+ @if $i == $index {
39
+ @if $value and $value != "" and $value != () {
40
+ $result: append($result, $value);
45
41
  }
46
-
47
- $result: append($result, nth($list, $i));
48
42
  }
43
+
44
+ $result: append($result, nth($list, $i));
49
45
  }
50
46
 
51
47
  @return $result;
@@ -19,31 +19,27 @@
19
19
  // @return [List] | false
20
20
 
21
21
  @function replace-nth($list, $index, $value) {
22
- $result: false;
23
-
24
22
  @if type-of($index) != number {
25
23
  @warn "List index #{$index} is not a number for `replace-nth`/`remove-nth`.";
26
- @return $result;
24
+ @return false;
27
25
  }
28
26
 
29
- @else if $index == 0 {
27
+ @if $index == 0 {
30
28
  @warn "List index 0 must be a non-zero integer for `replace-nth`/`remove-nth`.";
31
- @return $result;
29
+ @return false;
32
30
  }
33
31
 
34
- @else if abs($index) > length($list) {
32
+ @if abs($index) > length($list) {
35
33
  @warn "List index is #{$index} but list is only #{length($list)} item long for `replace-nth`/`remove-nth`.";
36
- @return $result;
34
+ @return false;
37
35
  }
38
36
 
39
- @else {
40
- $result: ();
41
- $index: if($index < 0, length($list) + $index + 1, $index);
37
+ $result: ();
38
+ $index: if($index < 0, length($list) + $index + 1, $index);
42
39
 
43
- @for $i from 1 through length($list) {
44
- @if $value and $value != "" and $value != () {
45
- $result: append($result, if($i == $index, $value, nth($list, $i)));
46
- }
40
+ @for $i from 1 through length($list) {
41
+ @if $value and $value != "" and $value != () {
42
+ $result: append($result, if($i == $index, $value, nth($list, $i)));
47
43
  }
48
44
  }
49
45
 
@@ -22,39 +22,35 @@
22
22
  // @return [List] | false
23
23
 
24
24
  @function slice($list, $start: 1, $end: length($list)) {
25
- $result: false;
26
-
27
25
  @if type-of($start) != number or type-of($end) != number {
28
26
  @warn "List indexes #{$start} and #{$end} must be numbers for `slice`.";
29
- @return $result;
27
+ @return false;
30
28
  }
31
29
 
32
- @else if $start > $end {
30
+ @if $start > $end {
33
31
  @warn "Start index is #{$start} but has to be lesser than or equals to the end index (#{$end}) for `slice`.";
34
- @return $result;
32
+ @return false;
35
33
  }
36
34
 
37
- @else if $start < 1 or $end < 1 {
35
+ @if $start < 1 or $end < 1 {
38
36
  @warn "List indexes must be non-zero integers for `slice`.";
39
- @return $result;
37
+ @return false;
40
38
  }
41
39
 
42
- @else if $start > length($list) {
40
+ @if $start > length($list) {
43
41
  @warn "Start index is #{$start} but list is only #{length($list)} items long for `slice`.";
44
- @return $result;
42
+ @return false;
45
43
  }
46
44
 
47
- @else if $end > length($list) {
45
+ @if $end > length($list) {
48
46
  @warn "End index is #{$end} but list is only #{length($list)} items long for `slice`.";
49
- @return $result;
47
+ @return false;
50
48
  }
51
49
 
52
- @else {
53
- $result: ();
54
-
55
- @for $i from $start through $end {
56
- $result: append($result, nth($list, $i));
57
- }
50
+ $result: ();
51
+
52
+ @for $i from $start through $end {
53
+ $result: append($result, nth($list, $i));
58
54
  }
59
55
 
60
56
  @return $result;
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.4.5
4
+ version: 0.4.6
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-12-06 00:00:00.000000000 Z
12
+ date: 2013-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sass