SassyLists 0.3.4 → 0.3.5

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.5`: improving `debug()`, `to-string()` and `chunk()`
3
4
  * `0.3.4`: fixing a minor issue in `insert-nth()`, `replace-nth()` and `prepend()`
4
5
  * `0.3.3`: removed dependence to `purge()` from all functions; fixed an issue with `sort()`; fixed an issue with error messages
5
6
  * `0.3.2`: removed dependence to `purge()` from `replace()`
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.3.4"
9
- DATE = "2013-11-06"
8
+ VERSION = "0.3.5"
9
+ DATE = "2013-11-09"
10
10
  end
11
11
 
12
12
  module Sass::Script::Functions
@@ -11,22 +11,30 @@
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
+ @if $size >= length($list) {
15
+ @return $list;
16
+ }
17
+
18
+ $index : 1;
19
+ $result : ();
20
+
21
+ @for $i from 1 through ceil(length($list) / $size) {
22
+ $tmp: ();
23
+
24
+ @for $j from 1 through $size {
25
+
26
+ @if $index <= length($list) {
17
27
 
18
- @for $i from 1 through $n-lists {
19
- $tmp-list: ();
28
+ $is-orphan: length($list) % $size == 1 and $j == 1;
29
+ $tmp: if($is-orphan, nth($list, $index), append($tmp, nth($list, $index)));
20
30
 
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
31
  }
32
+
33
+ $index: $index + 1;
25
34
  }
26
35
 
27
- $result: append($result, $tmp-list);
28
- $tmp-index: $tmp-index + $size;
36
+ $result: append($result, $tmp);
29
37
  }
30
38
 
31
39
  @return $result;
32
- }
40
+ }
@@ -12,18 +12,26 @@
12
12
  // @return [String]
13
13
 
14
14
  @function debug($list, $pre: false, $level: 1) {
15
- @debug $level;
16
15
  $tab : " ";
17
16
  $indent : "";
18
17
  $break : if($pre, "\A ", "");
18
+
19
+ @if length($list) == 0 {
20
+ @return "( )";
21
+ }
22
+
23
+ @if length($list) == 1 {
24
+ @return if($pre, "(" + type-of($list) + ") ", "") + $list;
25
+ }
19
26
 
20
27
  @for $i from 1 to $level {
21
- $indent : $indent + $tab;
28
+ $indent : $indent + $tab;
22
29
  }
23
30
 
24
31
  $result: "[" + $break;
25
32
 
26
- @each $item in $list {
33
+ @for $i from 1 through length($list) {
34
+ $item: nth($list, $i);
27
35
  $result: $result + if($pre, $indent + $tab, " ");
28
36
 
29
37
  @if length($item) > 1 {
@@ -33,12 +41,28 @@
33
41
  }
34
42
 
35
43
  @else {
36
- $result: $result
37
- + if($pre, "(" + type-of($item) + ") ", "")
38
- + $item;
44
+ @if $pre {
45
+ $result: $result + "(" + type-of($item) + ") ";
46
+ }
47
+
48
+ @if length($item) == 0 {
49
+ $result: $result + "( )";
50
+ }
51
+
52
+ @else if type-of($item) == string {
53
+ $result: $result + quote($item);
54
+ }
55
+
56
+ @else if $item == null {
57
+ $result: $result + "null";
58
+ }
59
+
60
+ @else {
61
+ $result: $result + $item;
62
+ }
39
63
  }
40
-
41
- @if index($list, $item) != length($list) {
64
+
65
+ @if $i != length($list) {
42
66
  $result: $result + "," + $break;
43
67
  }
44
68
  }
@@ -17,14 +17,15 @@
17
17
  @function to-string($list, $glue: '', $root: true) {
18
18
  $result: '';
19
19
 
20
- @each $item in $list {
20
+ @for $i from 1 through length($list) {
21
+ $item: nth($list, $i);
22
+
21
23
  @if length($item) > 1 {
22
24
  $result: $result + to-string($item, $glue, false);
23
25
  }
24
26
 
25
27
  @else {
26
- $condition: index($list, $item) != length($list) or not $root;
27
- $result: if($condition, $result + $item + $glue, $result + $item);
28
+ $result: if($i != length($list) or not $root, $result + $item + $glue, $result + $item);
28
29
  }
29
30
  }
30
31
 
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.3.4
4
+ version: 0.3.5
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-06 00:00:00.000000000 Z
12
+ date: 2013-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sass