SassyLists 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Changelog
2
2
 
3
+ * `0.2.2`: moving all comments to invisible
3
4
  * `0.2.1`: fixing an issue with `random-value()`
4
5
  * `0.2.0`: adding `random-value()`
5
6
  * `0.1.4`: fixing an issue with `sort()`, `is-symmetrical()`
data/lib/SassyLists.rb CHANGED
@@ -1,32 +1,14 @@
1
- # All gems that are required for this extension to work should go here.
2
- # These are the requires you would normally put in your config.rb file
3
- # By default, you should always included Compass. Do not include your
4
- # extension.
5
- require 'compass'
6
-
7
1
  require 'compass'
8
2
  extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
9
3
  Compass::Frameworks.register('SassyLists', :path => extension_path)
10
4
 
11
- # Version and date of version for your Compass extension.
12
- # Replace MyExtension with the name of your extension
13
- # Letters, numbers, and underscores only
14
- # Version is a number. If a version contains alphas, it will be created as
15
- # a prerelease version
5
+ # Version is a number. If a version contains alphas, it will be created as a prerelease version
16
6
  # Date is in the form of YYYY-MM-DD
17
7
  module SassyLists
18
- VERSION = "0.2.1"
19
- DATE = "2013-10-25"
8
+ VERSION = "0.2.2"
9
+ DATE = "2013-10-29"
20
10
  end
21
11
 
22
- # This is where any custom SassScript should be placed. The functions will be
23
- # available on require of your extension without the need for users to import
24
- # any partials. Uncomment below.
25
-
26
- # module Sass::Script::Functions
27
- #
28
- # end
29
-
30
12
  module Sass::Script::Functions
31
13
  def random(max = Sass::Script::Number.new(100))
32
14
  Sass::Script::Number.new(rand(max.value), max.numerator_units, max.denominator_units)
@@ -1,31 +1,31 @@
1
- /**
2
- * Chunk $list into $size large lists
3
- * -------------------------------------------------------------------------------
4
- * @example chunk( (a, b, c, d, e), 2 ) => a b, c d, e
5
- * @example chunk( (a, b, c, d, e), 3 ) => a b c, d e
6
- * @example chunk( a, 3 ) => a
7
- * -------------------------------------------------------------------------------
8
- * @param $list [List] : list
9
- * @param $size [Number] : length of lists
10
- * -------------------------------------------------------------------------------
11
- * @return [List]
12
- */
1
+ // Chunks $list into $size large lists
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#chunk
4
+ // -------------------------------------------------------------------------------
5
+ // @example chunk(a b c d e, 2) => a b, c d, e
6
+ // @example chunk(a b c d e, 3) => a b c, d e
7
+ // -------------------------------------------------------------------------------
8
+ // @param $list [List] : list
9
+ // @param $size [Number] : length of lists
10
+ // -------------------------------------------------------------------------------
11
+ // @return [List]
12
+
13
13
  @function chunk($list, $size) {
14
- $n: ceil(length($list) / $size);
15
- $temp-index: 0;
14
+ $n-lists: ceil(length($list) / $size);
15
+ $tmp-index: 0;
16
16
  $result: ();
17
17
 
18
- @for $i from 1 through $n {
19
- $temp-list: ();
18
+ @for $i from 1 through $n-lists {
19
+ $tmp-list: ();
20
20
 
21
- @for $j from 1 + $temp-index through $size + $temp-index {
21
+ @for $j from 1 + $tmp-index through $size + $tmp-index {
22
22
  @if $j <= length($list) {
23
- $temp-list: append($temp-list, nth($list, $j));
23
+ $tmp-list: append($tmp-list, nth($list, $j));
24
24
  }
25
25
  }
26
26
 
27
- $result: append($result, $temp-list);
28
- $temp-index: $temp-index + $size;
27
+ $result: append($result, $tmp-list);
28
+ $tmp-index: $tmp-index + $size;
29
29
  }
30
30
 
31
31
  @return $result;
@@ -1,16 +1,16 @@
1
- /**
2
- * Count the number of occurrences of each value of $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `replace-nth()`
5
- * -------------------------------------------------------------------------------
6
- * @example count-values( (a, b, c, d, e) ) => a 1, b 1, c 1, d 1, e 1
7
- * @example count-values( (a, b, c, a, d, b, a, e) ) => a 3, b 2, c 1, d 1, e 1
8
- * @example count-values( a ) => a 1
9
- * -------------------------------------------------------------------------------
10
- * @param $list [List] : list
11
- * -------------------------------------------------------------------------------
12
- * @return [List]
13
- */
1
+ // Counts the number of occurrences of each value of $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#count-values
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `replace-nth()`
6
+ // -------------------------------------------------------------------------------
7
+ // @example count-values(a b c d e) => a 1, b 1, c 1, d 1, e 1
8
+ // @example count-values(a b c a d b a e) => a 3, b 2, c 1, d 1, e 1
9
+ // -------------------------------------------------------------------------------
10
+ // @param $list [List] : list
11
+ // -------------------------------------------------------------------------------
12
+ // @return [List]
13
+
14
14
  @function count-values($list) {
15
15
  $keys : ();
16
16
  $counts : ();
@@ -1,16 +1,16 @@
1
- /**
2
- * Returns $list as a string
3
- * -------------------------------------------------------------------------------
4
- * @example debug( (a, b, c, d, e) ) => [ a, b, c, d, e ]
5
- * @example debug( (a b (c d e) ) ) => [ a, b, [ c, d, e ] ]
6
- * @example debug( a ) => [ a ]
7
- * -------------------------------------------------------------------------------
8
- * @param $list [List] : list
9
- * @param $type [Boolean] : enable/disable variables type
10
- * @param $root [Boolean] : strictly internal boolean for recursivity
11
- * -------------------------------------------------------------------------------
12
- * @return [String]
13
- */
1
+ // Returns $list as a string
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#debug
4
+ // -------------------------------------------------------------------------------
5
+ // @example debug(a b c d e) => [ a, b, c, d, e ]
6
+ // @example debug(a b (c d e)) => [ a, b, [ c, d, e ] ]
7
+ // -------------------------------------------------------------------------------
8
+ // @param $list [List] : list
9
+ // @param $type [Boolean] : enable/disable variables type
10
+ // @param $root [Boolean] : strictly internal boolean for recursivity
11
+ // -------------------------------------------------------------------------------
12
+ // @return [String]
13
+
14
14
  @function debug($list, $type: true, $root: true) {
15
15
  @if length($list) == 1 {
16
16
  @return if($type, quote("(#{type-of($list)}) #{$list}"), quote("#{$list}"));
@@ -44,11 +44,11 @@
44
44
  }
45
45
 
46
46
  /**
47
- * Mixin displaying clean debug
48
- * -------------------------------------------------------------------------------
49
- * @param $list [List] : list
50
- * @param $type [List] : enable/disable variables type
51
- */
47
+ // Mixin displaying clean debug
48
+ // -------------------------------------------------------------------------------
49
+ // @param $list [List] : list
50
+ // @param $type [List] : enable/disable variables type
51
+ ///
52
52
  @mixin debug($list, $type: true) {
53
53
  body:before {
54
54
  content: debug($list, $type) !important;
@@ -1,13 +1,13 @@
1
- /**
2
- * Returns first element of $list
3
- * -------------------------------------------------------------------------------
4
- * @example first( (a, b, c) ) => a
5
- * @example first( a ) => a
6
- * -------------------------------------------------------------------------------
7
- * @param $list [List] : list
8
- * -------------------------------------------------------------------------------
9
- * @return [Literal]
10
- */
1
+ // Returns first element of $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#first
4
+ // -------------------------------------------------------------------------------
5
+ // @example first(a b c) => a
6
+ // -------------------------------------------------------------------------------
7
+ // @param $list [List] : list
8
+ // -------------------------------------------------------------------------------
9
+ // @return [Literal]
10
+
11
11
  @function first($list) {
12
12
  @return nth($list, 1);
13
13
  }
@@ -1,38 +1,39 @@
1
- /**
2
- * Add $value at $index in $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `purge()`
5
- * -------------------------------------------------------------------------------
6
- * @example insert-nth( (a, b, c), 2, z ) => a, z, b, c
7
- * @example insert-nth( (a, b, c), 0, z ) => error
8
- * @example insert-nth( (a, b, c), -1, z ) => error
9
- * @example insert-nth( (a, b, c), 10, z ) => error
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * @param $index [Number] : index to add
13
- * @param $value [Literal] : value to add
14
- * -------------------------------------------------------------------------------
15
- * @raise [Error] if $index isn't an integer
16
- * @raise [Error] if $index is strictly lesser than 1
17
- * @raise [Error] if $index is strictly greater than length of $list
18
- * -------------------------------------------------------------------------------
19
- * @return [List] | false
20
- */
1
+ // Adds $value at $index in $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#insert-nth
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `purge()`
6
+ // -------------------------------------------------------------------------------
7
+ // @example insert-nth(a b c, 2, z) => a, z, b, c
8
+ // @example insert-nth(a b c, 0, z) => error
9
+ // @example insert-nth(a b c, -1, z) => error
10
+ // @example insert-nth(a b c, 10, z) => error
11
+ // -------------------------------------------------------------------------------
12
+ // @param $list [List] : list
13
+ // @param $index [Number] : index to add
14
+ // @param $value [Literal] : value to add
15
+ // -------------------------------------------------------------------------------
16
+ // @raise [Error] if $index isn't an integer
17
+ // @raise [Error] if $index is strictly lesser than 1
18
+ // @raise [Error] if $index is strictly greater than length of $list
19
+ // -------------------------------------------------------------------------------
20
+ // @return [List] | false
21
+
21
22
  @function insert-nth($list, $index, $value) {
22
23
  $result: false;
23
24
 
24
25
  @if type-of($index) != number {
25
- @warn "$index: #{quote($index)} is not a number for `insert-nth`.";
26
+ @warn "List index #{quote($index)} is not a number for `insert-nth`.";
26
27
  @return $result;
27
28
  }
28
29
 
29
30
  @else if $index < 1 {
30
- @warn "List index 0 must be a non-zero integer for `insert-nth`";
31
+ @warn "List index #{quote($index)} must be a non-zero integer for `insert-nth`";
31
32
  @return $result;
32
33
  }
33
34
 
34
35
  @else if $index > length($list) {
35
- @warn "List index is #{$index} but list is only #{length($list)} item long for `insert-nth'.";
36
+ @warn "List index is #{quote($index)} but list is only #{length($list)} items long for `insert-nth'.";
36
37
  @return $result;
37
38
  }
38
39
 
@@ -1,17 +1,17 @@
1
- /**
2
- * Test if $list is symmetrical (one-level deep)
3
- * -------------------------------------------------------------------------------
4
- * @dependence `reverse()`
5
- * -------------------------------------------------------------------------------
6
- * @example is-symmetrical( (a, b, c, d, e) ) => false
7
- * @example is-symmetrical( (a, b, c, b, a) ) => true
8
- * @example is-symmetrical( a ) => true
9
- * @example is-symmetrical( a, b c d, a ) => true
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * -------------------------------------------------------------------------------
13
- * @return [Boolean]
14
- */
1
+ // Checks whether $list is symmetrical (one-level deep)
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#is-symmetrical
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `reverse()`
6
+ // -------------------------------------------------------------------------------
7
+ // @example is-symmetrical(a b c d e) => false
8
+ // @example is-symmetrical(a b c b a) => true
9
+ // @example is-symmetrical(a (b c d) a) => true
10
+ // -------------------------------------------------------------------------------
11
+ // @param $list [List] : list
12
+ // -------------------------------------------------------------------------------
13
+ // @return [Boolean]
14
+
15
15
  @function is-symmetrical($list) {
16
16
  @return reverse($list) == reverse(reverse($list));
17
17
  }
@@ -1,17 +1,18 @@
1
- /**
2
- * Returns last index of $value in $list
3
- * -------------------------------------------------------------------------------
4
- * @example last-index( (a, b, c, a), a ) => 4
5
- * @example last-index( (a, b, c), z ) => null
6
- * -------------------------------------------------------------------------------
7
- * @param $list [List] : list
8
- * @param $value [Literal] : value to be searched for
9
- * -------------------------------------------------------------------------------
10
- * @return [Number] | null
11
- */
1
+ // Returns last index of $value in $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#last-index
4
+ // -------------------------------------------------------------------------------
5
+ // @example last-index(a b c a, a) => 4
6
+ // @example last-index(a b c, z) => null
7
+ // -------------------------------------------------------------------------------
8
+ // @param $list [List] : list
9
+ // @param $value [Literal] : value to be searched for
10
+ // -------------------------------------------------------------------------------
11
+ // @return [Number] | null
12
+
12
13
  @function last-index($list, $value) {
13
14
 
14
- @for $i from length($list) * -1 through -1 {
15
+ @for $i from length($list)// -1 through -1 {
15
16
  $i: abs($i);
16
17
 
17
18
  @if nth($list, $i) == $value {
@@ -1,13 +1,13 @@
1
- /**
2
- * Returns last element of $list
3
- * -------------------------------------------------------------------------------
4
- * @example last( (a, b, c) ) => c
5
- * @example last( a ) => a
6
- * -------------------------------------------------------------------------------
7
- * @param $list [List] : list
8
- * -------------------------------------------------------------------------------
9
- * @return [Literal]
10
- */
1
+ // Returns last element of $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#last
4
+ // -------------------------------------------------------------------------------
5
+ // @example last(a b c) => c
6
+ // -------------------------------------------------------------------------------
7
+ // @param $list [List] : list
8
+ // -------------------------------------------------------------------------------
9
+ // @return [Literal]
10
+
11
11
  @function last($list) {
12
12
  @return nth($list, length($list));
13
13
  }
@@ -1,15 +1,16 @@
1
- /**
2
- * Shift indexes from $list of $value
3
- * -------------------------------------------------------------------------------
4
- * @example loop( (a, b, c, d, e) ) => e, a, b, c, d
5
- * @example loop( (a, b, c, d, e), 2 ) => d, e, a, b, c
6
- * @example loop( (a, b, c, d, e), -2 ) => c, d, e, a, b
7
- * -------------------------------------------------------------------------------
8
- * @param $list [List] : list
9
- * @param $value [Number] : number of position between old and new indexes
10
- * -------------------------------------------------------------------------------
11
- * @return [List]
12
- */
1
+ // Shift indexes from $list of $value
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#loop
4
+ // -------------------------------------------------------------------------------
5
+ // @example loop(a b c d e) => e, a, b, c, d
6
+ // @example loop(a b c d e, 2) => d, e, a, b, c
7
+ // @example loop(a b c d e, -2) => c, d, e, a, b
8
+ // -------------------------------------------------------------------------------
9
+ // @param $list [List] : list
10
+ // @param $value [Number] : number of position between old and new indexes
11
+ // -------------------------------------------------------------------------------
12
+ // @return [List]
13
+
13
14
  @function loop($list, $value: 1) {
14
15
  $result: ();
15
16
 
@@ -1,16 +1,17 @@
1
- /**
2
- * Add $value as first index of $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `purge()`
5
- * -------------------------------------------------------------------------------
6
- * @example prepend( (a, b, c), z ) => z, a, b, c
7
- * @example prepend( (a, b, c), y z ) => y z, a, b, c
8
- * -------------------------------------------------------------------------------
9
- * @param $list [List] : list
10
- * @param $value [Literal] : value to prepend to the list
11
- * -------------------------------------------------------------------------------
12
- * @return [List]
13
- */
1
+ // Adds $value as first index of $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#prepend
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `purge()`
6
+ // -------------------------------------------------------------------------------
7
+ // @example prepend(a b c, z) => z, a, b, c
8
+ // @example prepend(a b c, y z) => y z, a, b, c
9
+ // -------------------------------------------------------------------------------
10
+ // @param $list [List] : list
11
+ // @param $value [Literal] : value to prepend to the list
12
+ // -------------------------------------------------------------------------------
13
+ // @return [List]
14
+
14
15
  @function prepend($list, $value) {
15
16
  @return purge(join($value, $list));
16
17
  }
@@ -1,13 +1,14 @@
1
- /**
2
- * Remove all false and null values from $list
3
- * -------------------------------------------------------------------------------
4
- * @example purge( (a, null, b, false, c, null) ) => a, b, c
5
- * @example purge( (a, b, c) ) => a, b, c
6
- * -------------------------------------------------------------------------------
7
- * @param $list [List] : list
8
- * -------------------------------------------------------------------------------
9
- * @return [List]
10
- */
1
+ // Removes all false and null values from $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation.html#purge
4
+ // -------------------------------------------------------------------------------
5
+ // @example purge(a null b false c) => a, b, c
6
+ // @example purge(a b c) => a, b, c
7
+ // -------------------------------------------------------------------------------
8
+ // @param $list [List] : list
9
+ // -------------------------------------------------------------------------------
10
+ // @return [List]
11
+
11
12
  @function purge($list) {
12
13
  $result: ();
13
14
 
@@ -1,14 +1,15 @@
1
- /**
2
- * Returns a random value of $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `rand` (Ruby)
5
- * -------------------------------------------------------------------------------
6
- * @example random-value( (a, b, c, d, e) ) => c
7
- * -------------------------------------------------------------------------------
8
- * @param $list [List] : List
9
- * -------------------------------------------------------------------------------
10
- * @return [Literal]
11
- */
1
+ // Returns a random value of $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation.html#random-value
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `rand` (Ruby)
6
+ // -------------------------------------------------------------------------------
7
+ // @example random-value(a b c d e) => c
8
+ // -------------------------------------------------------------------------------
9
+ // @param $list [List] : List
10
+ // -------------------------------------------------------------------------------
11
+ // @return [Literal]
12
+
12
13
  @function random-value($list) {
13
14
  @return nth($list, random(length($list)) + 1);
14
15
  }
@@ -1,14 +1,15 @@
1
- /**
2
- * Remove duplicate values from $list
3
- * -------------------------------------------------------------------------------
4
- * @example remove-duplicates( (a, b, a, c, b, d, c, e) ) => a, b, c, d, e
5
- * @example remove-duplicates( (a, b, (c, c, c)) ) => a, b, c
6
- * -------------------------------------------------------------------------------
7
- * @param $list [List] : list
8
- * @param $recursive [Boolean] : enable / disable recursivity
9
- * -------------------------------------------------------------------------------
10
- * @return [List]
11
- */
1
+ // Removes duplicate values from $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#remove-duplicates
4
+ // -------------------------------------------------------------------------------
5
+ // @example remove-duplicates(a b a c b d c e) => a, b, c, d, e
6
+ // @example remove-duplicates(a b (c c c), true) => a, b, c
7
+ // -------------------------------------------------------------------------------
8
+ // @param $list [List] : list
9
+ // @param $recursive [Boolean] : enable / disable recursivity
10
+ // -------------------------------------------------------------------------------
11
+ // @return [List]
12
+
12
13
  @function remove-duplicates($list, $recursive: false) {
13
14
  $result: ();
14
15
 
@@ -1,23 +1,24 @@
1
- /**
2
- * Remove value from $list at index $index
3
- * -------------------------------------------------------------------------------
4
- * @dependence `replace-nth()`
5
- * -------------------------------------------------------------------------------
6
- * @example remove-nth( (a, b, c), 2 ) => a, c
7
- * @example remove-nth( (a, b, c), 0 ) => error
8
- * @example remove-nth( (a, b, c), -1 ) => a, b
9
- * @example remove-nth( (a, b, c), 10 ) => error
10
- * @example remove-nth( (a, b, c), -10 ) => error
11
- * -------------------------------------------------------------------------------
12
- * @param $list [List] : list
13
- * @param $index [Number] : index to remove
14
- * -------------------------------------------------------------------------------
15
- * @raise [Error] if $index isn't an integer
16
- * @raise [Error] if $index is 0
17
- * @raise [Error] if abs value of $index is strictly greater then length of $list
18
- * -------------------------------------------------------------------------------
19
- * @return [List] | false
20
- */
1
+ // Removes value from $list at index $index
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#remove-nth
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `replace-nth()`
6
+ // -------------------------------------------------------------------------------
7
+ // @example remove-nth(a b c, 2) => a, c
8
+ // @example remove-nth(a b c, 0) => error
9
+ // @example remove-nth(a b c, -1) => a, b
10
+ // @example remove-nth(a b c, 10) => error
11
+ // @example remove-nth(a b c, -10) => error
12
+ // -------------------------------------------------------------------------------
13
+ // @param $list [List] : list
14
+ // @param $index [Number] : index to remove
15
+ // -------------------------------------------------------------------------------
16
+ // @raise [Error] if $index isn't an integer
17
+ // @raise [Error] if $index is 0
18
+ // @raise [Error] if abs value of $index is strictly greater then length of $list
19
+ // -------------------------------------------------------------------------------
20
+ // @return [List] | false
21
+
21
22
  @function remove-nth($list, $index) {
22
23
  @return replace-nth($list, $index, "");
23
24
  }
@@ -1,19 +1,20 @@
1
- /**
2
- * Remove value(s) $value from $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `replace()`
5
- * -------------------------------------------------------------------------------
6
- * @example remove( (a, b, c), b ) => a, c
7
- * @example remove( (a, b, c), z ) => a, b, c
8
- * @example remove( (a, b, c b), b ) => a, c b
9
- * @example remove( (a, b, c b), b, true ) => a, c
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * @param $value [Literal] : value to remove
13
- * @param $recursive [Boolean] : enable / disable recursivity
14
- * -------------------------------------------------------------------------------
15
- * @return [List]
16
- */
1
+ // Removes value(s) $value from $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#remove
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `replace()`
6
+ // -------------------------------------------------------------------------------
7
+ // @example remove(a b c, b) => a, c
8
+ // @example remove(a b c, z) => a, b, c
9
+ // @example remove(a b c b, b) => a, c b
10
+ // @example remove(a b c b, b, true) => a, c
11
+ // -------------------------------------------------------------------------------
12
+ // @param $list [List] : list
13
+ // @param $value [Literal] : value to remove
14
+ // @param $recursive [Boolean] : enable / disable recursivity
15
+ // -------------------------------------------------------------------------------
16
+ // @return [List]
17
+
17
18
  @function remove($list, $value, $recursive: false) {
18
19
  @return replace($list, $value, "", $recursive);
19
20
  }
@@ -1,29 +1,30 @@
1
- /**
2
- * Replace value at $index from $list by $value
3
- * -------------------------------------------------------------------------------
4
- * @dependence `purge()`
5
- * -------------------------------------------------------------------------------
6
- * @example replace-nth( (a, b, c), 2, z ) => a, z, c
7
- * @example replace-nth( (a, b, c), 0, z ) => error
8
- * @example replace-nth( (a, b, c), -1, z ) => a, b, z
9
- * @example replace-nth( (a, b, c), 10, z ) => error
10
- * @example replace-nth( (a, b, c), -10, z ) => error
11
- * -------------------------------------------------------------------------------
12
- * @param $list [List] : list
13
- * @param $index [Number] : index to update
14
- * @param $value [Literal] : new value for index $index
15
- * -------------------------------------------------------------------------------
16
- * @raise [Error] if $index isn't an integer
17
- * @raise [Error] if $index is 0
18
- * @raise [Error] if abs value of $index is strictly greater than length of $list
19
- * -------------------------------------------------------------------------------
20
- * @return [List] | false
21
- */
1
+ // Replaces value at $index from $list by $value
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#replace-nth
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `purge()`
6
+ // -------------------------------------------------------------------------------
7
+ // @example replace-nth(a b c, 2, z) => a, z, c
8
+ // @example replace-nth(a b c, 0, z) => error
9
+ // @example replace-nth(a b c, 10, z) => error
10
+ // @example replace-nth(a b c, -1, z) => a, b, z
11
+ // @example replace-nth(a b c, -10, z) => error
12
+ // -------------------------------------------------------------------------------
13
+ // @param $list [List] : list
14
+ // @param $index [Number] : index to update
15
+ // @param $value [Literal] : new value for index $index
16
+ // -------------------------------------------------------------------------------
17
+ // @raise [Error] if $index isn't an integer
18
+ // @raise [Error] if $index is 0
19
+ // @raise [Error] if abs value of $index is strictly greater than length of $list
20
+ // -------------------------------------------------------------------------------
21
+ // @return [List] | false
22
+
22
23
  @function replace-nth($list, $index, $value) {
23
24
  $result: false;
24
25
 
25
26
  @if type-of($index) != number {
26
- @warn "$index: #{quote($index)} is not a number for `replace-nth`/`remove-nth`.";
27
+ @warn "List index #{quote($index)} is not a number for `replace-nth`/`remove-nth`.";
27
28
  @return $result;
28
29
  }
29
30
 
@@ -33,7 +34,7 @@
33
34
  }
34
35
 
35
36
  @else if abs($index) > length($list) {
36
- @warn "List index is #{$index} but list is only #{length($list)} item long for `replace-nth`/`remove-nth`.";
37
+ @warn "List index is #{quote($index)} but list is only #{length($list)} item long for `replace-nth`/`remove-nth`.";
37
38
  @return $result;
38
39
  }
39
40
 
@@ -1,20 +1,21 @@
1
- /**
2
- * Replace $old-value by $new-value in $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `purge()`
5
- * -------------------------------------------------------------------------------
6
- * @example replace( (a, b, c), b, z ) => a, z, c
7
- * @example replace( (a, b, c), y, z ) => a, b, c
8
- * @example replace( (a, b, c a), a, z ) => z, b, c z
9
- * @example replace( (a, b, c a), a, z, true ) => z, b, c z
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * @param $old-value [Literal] : value to replace
13
- * @param $new-value [Literal] : new value for $old-value
14
- * @param $recursive [Boolean] : enable / disable recursivity
15
- * -------------------------------------------------------------------------------
16
- * @return [List]
17
- */
1
+ // Replaces $old-value by $new-value in $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation.html#replace
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `purge()`
6
+ // -------------------------------------------------------------------------------
7
+ // @example replace( (a, b, c), b, z ) => a, z, c
8
+ // @example replace( (a, b, c), y, z ) => a, b, c
9
+ // @example replace( (a, b, c a), a, z ) => z, b, c z
10
+ // @example replace( (a, b, c a), a, z, true ) => z, b, c z
11
+ // -------------------------------------------------------------------------------
12
+ // @param $list [List] : list
13
+ // @param $old-value [Literal] : value to replace
14
+ // @param $new-value [Literal] : new value for $old-value
15
+ // @param $recursive [Boolean] : enable / disable recursivity
16
+ // -------------------------------------------------------------------------------
17
+ // @return [List]
18
+
18
19
  @function replace($list, $old-value, $new-value, $recursive: false) {
19
20
  $result: ();
20
21
 
@@ -1,20 +1,20 @@
1
- /**
2
- * Reverses the order of $list
3
- * -------------------------------------------------------------------------------
4
- * @example reverse( (a, b, c) ) => c, b, a
5
- * @example reverse( (a, b, c a) ) => c a, b, a
6
- * @example reverse( (a, b, c a), true ) => a c, b, a
7
- * @example reverse( a ) => a
8
- * -------------------------------------------------------------------------------
9
- * @param $list [List] : list
10
- * @param $recursive [Boolean] : enable / disable recursivity
11
- * -------------------------------------------------------------------------------
12
- * @return [List]
13
- */
1
+ // Reverses the order of $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#reverse
4
+ // -------------------------------------------------------------------------------
5
+ // @example reverse(a b c) => c, b, a
6
+ // @example reverse(a b (c a)) => c a, b, a
7
+ // @example reverse(a b (c a), true) => a c, b, a
8
+ // -------------------------------------------------------------------------------
9
+ // @param $list [List] : list
10
+ // @param $recursive [Boolean] : enable / disable recursivity
11
+ // -------------------------------------------------------------------------------
12
+ // @return [List]
13
+
14
14
  @function reverse($list, $recursive: false) {
15
15
  $result: ();
16
16
 
17
- @for $i from length($list) * -1 through -1 {
17
+ @for $i from length($list)// -1 through -1 {
18
18
  $item: nth($list, abs($i));
19
19
 
20
20
  @if length($item) > 1 and $recursive {
@@ -1,35 +1,36 @@
1
- /**
2
- * Slices $list between $start and $end
3
- * -------------------------------------------------------------------------------
4
- * @example slice( (a, b, c, d), 2, 3 ) => b, c
5
- * @example slice( (a, b, c, d), 3, 2 ) => error
6
- * @example slice( (a, b, c, d), 3, 5 ) => error
7
- * @example slice( (a, b, c, d), -1, 3 ) => error
8
- * @example slice( (a, b, c, d), 0, 3 ) => error
9
- * @example slice( (a, b, c, d), 3, 3 ) => c
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * @param $start [Number] : start index
13
- * @param $end [Number] : end index
14
- * -------------------------------------------------------------------------------
15
- * @raise [Error] if $start or $end aren't integers
16
- * @raise [Error] if $start is greater than $end
17
- * @raise [Error] if $start or $end is strictly lesser than 1
18
- * @raise [Error] if $start is strictly greater than length of $list
19
- * @raise [Error] if $end is strictly greater than length of $list
20
- * -------------------------------------------------------------------------------
21
- * @return [List] | false
22
- */
1
+ // Slices $list between $start and $end
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#slice
4
+ // -------------------------------------------------------------------------------
5
+ // @example slice(a b c d, 2, 3) => b, c
6
+ // @example slice(a b c d, 3, 2) => error
7
+ // @example slice(a b c d, 3, 5) => error
8
+ // @example slice(a b c d, -1, 3) => error
9
+ // @example slice(a b c d, 0, 3) => error
10
+ // @example slice(a b c d, 3, 3) => c
11
+ // -------------------------------------------------------------------------------
12
+ // @param $list [List] : list
13
+ // @param $start [Number] : start index
14
+ // @param $end [Number] : end index
15
+ // -------------------------------------------------------------------------------
16
+ // @raise [Error] if $start or $end aren't integers
17
+ // @raise [Error] if $start is greater than $end
18
+ // @raise [Error] if $start or $end is strictly lesser than 1
19
+ // @raise [Error] if $start is strictly greater than length of $list
20
+ // @raise [Error] if $end is strictly greater than length of $list
21
+ // -------------------------------------------------------------------------------
22
+ // @return [List] | false
23
+
23
24
  @function slice($list, $start: 1, $end: length($list)) {
24
25
  $result: false;
25
26
 
26
27
  @if type-of($start) != number or type-of($end) != number {
27
- @warn "Either $start or $end are not a number for `slice`.";
28
+ @warn "List indexes #{quote($start)} and #{quote($end)} must be numbers for `slice`.";
28
29
  @return $result;
29
30
  }
30
31
 
31
32
  @else if $start > $end {
32
- @warn "The start index has to be lesser than or equals to the end index for `slice`.";
33
+ @warn "Start index is #{quote($start)} but has to be lesser than or equals to the end index (#{quote($end)}) for `slice`.";
33
34
  @return $result;
34
35
  }
35
36
 
@@ -39,12 +40,12 @@
39
40
  }
40
41
 
41
42
  @else if $start > length($list) {
42
- @warn "List index is #{$start} but list is only #{length($list)} item long for `slice`.";
43
+ @warn "Start index is #{quote($start)} but list is only #{length($list)} items long for `slice`.";
43
44
  @return $result;
44
45
  }
45
46
 
46
47
  @else if $end > length($list) {
47
- @warn "List index is #{$end} but list is only #{length($list)} item long for `slice`.";
48
+ @warn "End index is #{quote($end)} but list is only #{length($list)} items long for `slice`.";
48
49
  @return $result;
49
50
  }
50
51
 
@@ -1,45 +1,57 @@
1
- /**
2
- * Sort numeric values of $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `last()`
5
- * @dependence `insert-nth()`
6
- * -------------------------------------------------------------------------------
7
- * @example sort( (5, 12, 4.7, 6, 69, 6) ) => 4.7, 5, 6, 6, 12, 69
8
- * @example sort( (5, 12, 4.7, "8", 6, 14px, 69, 6) ) => 4.7, 5, 6, 6, 12, 69
9
- * @example sort( 1 ) => 1
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * -------------------------------------------------------------------------------
13
- * @raise [Warning] if not unitless number found
14
- * -------------------------------------------------------------------------------
15
- * @return [List]
16
- */
1
+ // Sorts numeric values of $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#sort
4
+ // -------------------------------------------------------------------------------
5
+ // @dependence `last()`
6
+ // @dependence `insert-nth()`
7
+ // -------------------------------------------------------------------------------
8
+ // @example sort(5 12 4.7 6 69 6) => 4.7, 5, 6, 6, 12, 69
9
+ // @example sort(5 12 4.7 "8" 6 14px 69 6) => 4.7, 5, 6, 6, 12, 69
10
+ // -------------------------------------------------------------------------------
11
+ // @param $list [List] : list
12
+ // -------------------------------------------------------------------------------
13
+ // @raise [Warning] if not unitless number found
14
+ // -------------------------------------------------------------------------------
15
+ // @return [List]
16
+
17
17
  @function sort($list, $force: false) {
18
18
  $result : nth($list, 1);
19
19
 
20
20
  @if length($list) > 1 {
21
+
21
22
  @for $i from 2 through length($list) {
22
23
  $item: nth($list, $i);
24
+
23
25
  @if type-of($item) == number {
26
+
24
27
  @if unitless($item) and $force {
28
+
25
29
  @if $item > last($result) {
26
30
  $result: append($result, $item);
27
31
  }
32
+
28
33
  @else {
29
34
  $index: 0;
35
+
30
36
  @for $i from length($result)*-1 through -1 {
31
37
  $i: abs($i);
38
+
32
39
  @if $item <= nth($result, $i) {
33
40
  $index: $i;
34
41
  }
35
42
  }
43
+
36
44
  $result: insert-nth($result, $index, $item);
37
45
  }
46
+
38
47
  }
48
+
39
49
  @else {
40
50
  @warn "Not unitless number found. Omitted.";
41
51
  }
52
+
42
53
  }
54
+
43
55
  @else {
44
56
  @warn "Not integer value found. Omitted.";
45
57
  }
@@ -1,16 +1,17 @@
1
- /**
2
- * Sum up all unitless values in $list
3
- * -------------------------------------------------------------------------------
4
- * @example sum( (1 2 3 4 5) ) => 15
5
- * @example sum( (1 a 2 b 3) ) => 6
6
- * @example sum( (10px 3em 5%) ) => 0
7
- * @example sum( (10px 3em 5%, true) ) => 18
8
- * -------------------------------------------------------------------------------
9
- * @param $list [List] : list
10
- * @param $force [Boolean] : enable / disable parseInt
11
- * -------------------------------------------------------------------------------
12
- * @return [Number]
13
- */
1
+ // Sums up all unitless values in $list
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#sum
4
+ // -------------------------------------------------------------------------------
5
+ // @example sum(1 2 3 4 5) => 15
6
+ // @example sum(1 a 2 b 3) => 6
7
+ // @example sum(10px 3em 5%) => 0
8
+ // @example sum(10px 3em 5%, true) => 18
9
+ // -------------------------------------------------------------------------------
10
+ // @param $list [List] : list
11
+ // @param $force [Boolean] : enable / disable parseInt
12
+ // -------------------------------------------------------------------------------
13
+ // @return [Number]
14
+
14
15
  @function sum($list, $force: false) {
15
16
  $result: 0;
16
17
 
@@ -18,7 +19,7 @@
18
19
  @if type-of($item) == number {
19
20
 
20
21
  @if $force and unit($item) {
21
- $item: $item / ($item * 0 + 1);
22
+ $item: $item / ($item// 0 + 1);
22
23
  }
23
24
 
24
25
  @if unitless($item) {
@@ -1,16 +1,17 @@
1
- /**
2
- * Joins all elements of $list with $glue
3
- * -------------------------------------------------------------------------------
4
- * @example to-string( (a, b, c) ) => abc
5
- * @example to-string( (a, b, c), '-' ) => a-b-c
6
- * @example to-string( (a, b c, d) ) => abcd
7
- * -------------------------------------------------------------------------------
8
- * @param $list [List] : list
9
- * @param $glue [String] : value to use as a join string
10
- * @param $root [Boolean] : strictly internal boolean for recursivity
11
- * -------------------------------------------------------------------------------
12
- * @return [String]
13
- */
1
+ // Joins all elements of $list with $glue
2
+ // -------------------------------------------------------------------------------
3
+ // @documentation http://sassylists.com/documentation/#to-string
4
+ // -------------------------------------------------------------------------------
5
+ // @example to-string(a b c) => abc
6
+ // @example to-string(a (b c) d) => abcd
7
+ // @example to-string(a b c, '-') => a-b-c
8
+ // -------------------------------------------------------------------------------
9
+ // @param $list [List] : list
10
+ // @param $glue [String] : value to use as a join string
11
+ // @param $root [Boolean] : strictly internal boolean for recursivity
12
+ // -------------------------------------------------------------------------------
13
+ // @return [String]
14
+
14
15
  @function to-string($list, $glue: '', $root: true) {
15
16
  $result: null;
16
17
 
@@ -1,78 +1,10 @@
1
- /* ------------------------------------------------------------------------------- *
2
- * SassyLists - A couple of advanced Sass list functions
3
- * ------------------------------------------------------------------------------- *
4
- *
5
- * chunk($list, $size)
6
- * Chunk $list into $size large lists
7
- *
8
- * count-values($list)
9
- * Count the number of occurrences of each value of $list
10
- *
11
- * debug($list)
12
- * Returns $list as a string
13
- *
14
- * first($list)
15
- * Return first element of $list
16
- *
17
- * insert-nth($list, $index, $value)
18
- * Add $value at $index in $list
19
- *
20
- * is-symmetrical($list)
21
- * Check if $list is symmetrical
22
- *
23
- * last($list)
24
- * Return last element of $list
25
- *
26
- * last-index($list, $value)
27
- * Return last index of $value in $list
28
- *
29
- * loop($list, $value: 1)
30
- * Shift indexes from $list of $value
31
- *
32
- * prepend($list, $value)
33
- * Add $value as first index of $list
34
- *
35
- * purge($list)
36
- * Remove all false and null values from $list
37
- *
38
- * random-value($list)
39
- * Return random value from $list
40
- *
41
- * remove($list, $value, $recursive: false)
42
- * Remove value(s) $value from $list
43
- *
44
- * remove-duplicates($list, $recursive: false)
45
- * Remove duplicate values from $list
46
- *
47
- * remove-nth($list, $index)
48
- * Remove value from $list at index $index
49
- *
50
- * replace($list, $old-value, $new-value, $recursive: false)
51
- * Replace $old-value by $new-value in $list
52
- *
53
- * replace-nth($list, $index, $value)
54
- * Replace value at $index from $list by $value
55
- *
56
- * reverse($list, $recursive: false)
57
- * Reverse the order of $list
58
- *
59
- * slice($list, $start: 1, $end: length($list))
60
- * Slice $list between $start and $end
61
- *
62
- * sort($list)
63
- * Sort all numeric values in $list
64
- *
65
- * sum($list, $force: false)
66
- * Sum up all unitless values in $list
67
- *
68
- * to-string($list, $glue: '', $is-nested: false)
69
- * Join all elements of $list with $glue
70
- *
71
- * ------------------------------------------------------------------------------- *
72
- * CodePen (SCSS): http://codepen.io/HugoGiraudel/pen/loAgq
73
- * CodePen (Sass): http://codepen.io/HugoGiraudel/pen/BskrE
74
- * Repository: https://github.com/Team-Sass/Sass-list-functions/
75
- * ------------------------------------------------------------------------------- */
1
+ // -------------------------------------------------------------------------------
2
+ // SassyLists - A couple of advanced Sass list functions
3
+ // -------------------------------------------------------------------------------
4
+ // Official site: http://sassylists.com/
5
+ // CodePen: http://codepen.io/HugoGiraudel/pen/loAgq
6
+ // Repository: https://github.com/Team-Sass/SassyLists/
7
+ // -------------------------------------------------------------------------------
76
8
 
77
9
  @import "SassyLists/chunk";
78
10
  @import "SassyLists/count-values";
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.1
4
+ version: 0.2.2
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-10-25 00:00:00.000000000 Z
12
+ date: 2013-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sass
@@ -50,7 +50,6 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
- - readme.md
54
53
  - CHANGELOG.md
55
54
  - lib/SassyLists.rb
56
55
  - stylesheets/SassyLists/_chunk.scss
@@ -76,7 +75,7 @@ files:
76
75
  - stylesheets/SassyLists/_sum.scss
77
76
  - stylesheets/SassyLists/_to-string.scss
78
77
  - stylesheets/_SassyLists.scss
79
- homepage: https://github.com/Team-Sass/Sass-list-functions
78
+ homepage: http://sassylists.com/
80
79
  licenses: []
81
80
  post_install_message:
82
81
  rdoc_options: []
data/readme.md DELETED
@@ -1,30 +0,0 @@
1
- SassyLists - Advanced Sass list functions
2
- =========================================
3
-
4
- Here are a couple of advanced Sass (SCSS) list functions you may or may not need in your projects. Including:
5
-
6
- * `chunk()`: chunk list into size large lists
7
- * `count-values()`: count the number of occurrences of each value of list
8
- * `debug()`: returns list as a string
9
- * `first()`: return first item in list
10
- * `insert-nth()`: insert value at index
11
- * `is-symmetrical()`: check if list is symmetrical
12
- * `last()`: return last item in list
13
- * `last-index()`: return last index of value in list
14
- * `loop()`: shift indexes in list
15
- * `prepend()`: prepend value to list
16
- * `purge()`: remove all `false` and `null` values from list
17
- * `remove()`: remove value in list
18
- * `remove-duplicates()`: remove duplicate values from list
19
- * `remove-nth()`: remove value at index
20
- * `replace()`: replace value in list
21
- * `replace-nth()`: replace value at index
22
- * `reverse()`: reverse list
23
- * `slice()`: slice list
24
- * `sort()`: sort list
25
- * `sum()`: sum all unitless values in list
26
- * `to-string()`: cast list as string (JS `.join()`)
27
-
28
- Some functions depend on other functions. If you include functions individually, make sure to check for these dependencies in their respective docs.
29
-
30
- If you ever need to use them in one of your pen at [CodePen](http://codepen.io), just link to http://codepen.io/HugoGiraudel/pen/loAgq as an extra CSS resource. You'll have instant access to all functions.