SassyLists 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/SassyLists.rb +30 -0
- data/readme.md +30 -0
- data/stylesheets/SassyLists/_chunk.scss +32 -0
- data/stylesheets/SassyLists/_count-values.scss +33 -0
- data/stylesheets/SassyLists/_debug.scss +34 -0
- data/stylesheets/SassyLists/_first.scss +13 -0
- data/stylesheets/SassyLists/_insert-nth.scss +52 -0
- data/stylesheets/SassyLists/_is-symmetrical.scss +23 -0
- data/stylesheets/SassyLists/_last-index.scss +24 -0
- data/stylesheets/SassyLists/_last.scss +13 -0
- data/stylesheets/SassyLists/_loop.scss +21 -0
- data/stylesheets/SassyLists/_prepend.scss +16 -0
- data/stylesheets/SassyLists/_purge.scss +21 -0
- data/stylesheets/SassyLists/_remove-duplicates.scss +30 -0
- data/stylesheets/SassyLists/_remove-nth.scss +23 -0
- data/stylesheets/SassyLists/_remove.scss +19 -0
- data/stylesheets/SassyLists/_replace-nth.scss +50 -0
- data/stylesheets/SassyLists/_replace.scss +32 -0
- data/stylesheets/SassyLists/_reverse.scss +30 -0
- data/stylesheets/SassyLists/_slice.scss +60 -0
- data/stylesheets/SassyLists/_sort.scss +42 -0
- data/stylesheets/SassyLists/_sum.scss +32 -0
- data/stylesheets/SassyLists/_to-string.scss +29 -0
- data/stylesheets/_SassyLists.scss +94 -0
- metadata +101 -0
data/lib/SassyLists.rb
ADDED
@@ -0,0 +1,30 @@
|
|
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
|
+
# This tells Compass what your Compass extension is called, and where to find
|
8
|
+
# its files
|
9
|
+
# Replace 'ListFunctions' with the name of your extension. Spaces allowed.
|
10
|
+
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
11
|
+
Compass::Frameworks.register('SassyLists', :path => extension_path)
|
12
|
+
|
13
|
+
# Version and date of version for your Compass extension.
|
14
|
+
# Replace MyExtension with the name of your extension
|
15
|
+
# Letters, numbers, and underscores only
|
16
|
+
# Version is a number. If a version contains alphas, it will be created as
|
17
|
+
# a prerelease version
|
18
|
+
# Date is in the form of YYYY-MM-DD
|
19
|
+
module SassyLists
|
20
|
+
VERSION = "0.1"
|
21
|
+
DATE = "2013-10-16"
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is where any custom SassScript should be placed. The functions will be
|
25
|
+
# available on require of your extension without the need for users to import
|
26
|
+
# any partials. Uncomment below.
|
27
|
+
|
28
|
+
# module Sass::Script::Functions
|
29
|
+
#
|
30
|
+
# end
|
data/readme.md
ADDED
@@ -0,0 +1,30 @@
|
|
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.
|
@@ -0,0 +1,32 @@
|
|
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
|
+
*/
|
13
|
+
@function chunk($list, $size) {
|
14
|
+
$n: ceil(length($list) / $size);
|
15
|
+
$temp-index: 0;
|
16
|
+
$result: ();
|
17
|
+
|
18
|
+
@for $i from 1 through $n {
|
19
|
+
$temp-list: ();
|
20
|
+
|
21
|
+
@for $j from 1 + $temp-index through $size + $temp-index {
|
22
|
+
@if $j <= length($list) {
|
23
|
+
$temp-list: append($temp-list, nth($list, $j));
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
$result: append($result, $temp-list);
|
28
|
+
$temp-index: $temp-index + $size;
|
29
|
+
}
|
30
|
+
|
31
|
+
@return $result;
|
32
|
+
}
|
@@ -0,0 +1,33 @@
|
|
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
|
+
*/
|
14
|
+
@function count-values($list) {
|
15
|
+
$keys : ();
|
16
|
+
$counts : ();
|
17
|
+
|
18
|
+
@each $item in $list {
|
19
|
+
$index: index($keys, $item);
|
20
|
+
|
21
|
+
@if not $index {
|
22
|
+
$keys : append($keys, $item);
|
23
|
+
$counts : append($counts, 1);
|
24
|
+
}
|
25
|
+
|
26
|
+
@else {
|
27
|
+
$count : nth($counts, $index) + 1;
|
28
|
+
$counts : replace-nth($counts, $index, $count);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
@return zip($keys, $counts);
|
33
|
+
}
|
@@ -0,0 +1,34 @@
|
|
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
|
+
* -------------------------------------------------------------------------------
|
10
|
+
* @return [String]
|
11
|
+
*/
|
12
|
+
@function debug($list) {
|
13
|
+
$result: #{"[ "};
|
14
|
+
|
15
|
+
@each $item in $list {
|
16
|
+
|
17
|
+
@if length($item) > 1 {
|
18
|
+
$result: $result#{debug($item)};
|
19
|
+
}
|
20
|
+
|
21
|
+
@else {
|
22
|
+
$result: $result#{$item};
|
23
|
+
}
|
24
|
+
|
25
|
+
@if index($list, $item) != length($list) {
|
26
|
+
$result: $result#{", "};
|
27
|
+
}
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
$result: $result#{" ]"};
|
32
|
+
|
33
|
+
@return quote($result);
|
34
|
+
}
|
@@ -0,0 +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
|
+
*/
|
11
|
+
@function first($list) {
|
12
|
+
@return nth($list, 1);
|
13
|
+
}
|
@@ -0,0 +1,52 @@
|
|
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
|
+
*/
|
21
|
+
@function insert-nth($list, $index, $value) {
|
22
|
+
$result: false;
|
23
|
+
|
24
|
+
@if type-of($index) != number {
|
25
|
+
@warn "$index: #{quote($index)} is not a number for `insert-nth`.";
|
26
|
+
@return $result;
|
27
|
+
}
|
28
|
+
|
29
|
+
@else if $index < 1 {
|
30
|
+
@warn "List index 0 must be a non-zero integer for `insert-nth`";
|
31
|
+
@return $result;
|
32
|
+
}
|
33
|
+
|
34
|
+
@else if $index > length($list) {
|
35
|
+
@warn "List index is #{$index} but list is only #{length($list)} item long for `insert-nth'.";
|
36
|
+
@return $result;
|
37
|
+
}
|
38
|
+
|
39
|
+
@else {
|
40
|
+
$result: ();
|
41
|
+
|
42
|
+
@for $i from 1 through length($list) {
|
43
|
+
@if $i == $index {
|
44
|
+
$result: append($result, $value);
|
45
|
+
}
|
46
|
+
|
47
|
+
$result: append($result, nth($list, $i));
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
@return purge($result);
|
52
|
+
}
|
@@ -0,0 +1,23 @@
|
|
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
|
+
*/
|
15
|
+
@function is-symmetrical($list) {
|
16
|
+
$result: ();
|
17
|
+
|
18
|
+
@each $item in $list {
|
19
|
+
$result: append($result, $item, space);
|
20
|
+
}
|
21
|
+
|
22
|
+
@return $result == reverse($result);
|
23
|
+
}
|
@@ -0,0 +1,24 @@
|
|
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
|
+
*/
|
12
|
+
@function last-index($list, $value) {
|
13
|
+
|
14
|
+
@for $i from length($list) * -1 through -1 {
|
15
|
+
$i: abs($i);
|
16
|
+
|
17
|
+
@if nth($list, $i) == $value {
|
18
|
+
@return $i;
|
19
|
+
}
|
20
|
+
|
21
|
+
}
|
22
|
+
|
23
|
+
@return null;
|
24
|
+
}
|
@@ -0,0 +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
|
+
*/
|
11
|
+
@function last($list) {
|
12
|
+
@return nth($list, length($list));
|
13
|
+
}
|
@@ -0,0 +1,21 @@
|
|
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
|
+
*/
|
13
|
+
@function loop($list, $value: 1) {
|
14
|
+
$result: ();
|
15
|
+
|
16
|
+
@for $i from 0 to length($list) {
|
17
|
+
$result: append($result, nth($list, ($i - $value) % length($list) + 1));
|
18
|
+
}
|
19
|
+
|
20
|
+
@return $result;
|
21
|
+
}
|
@@ -0,0 +1,16 @@
|
|
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
|
+
*/
|
14
|
+
@function prepend($list, $value) {
|
15
|
+
@return purge(join($value, $list));
|
16
|
+
}
|
@@ -0,0 +1,21 @@
|
|
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
|
+
*/
|
11
|
+
@function purge($list) {
|
12
|
+
$result: ();
|
13
|
+
|
14
|
+
@each $item in $list {
|
15
|
+
@if $item != null and $item != false and $item != "" {
|
16
|
+
$result: append($result, $item);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
@return $result;
|
21
|
+
}
|
@@ -0,0 +1,30 @@
|
|
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
|
+
*/
|
12
|
+
@function remove-duplicates($list, $recursive: false) {
|
13
|
+
$result: ();
|
14
|
+
|
15
|
+
@each $item in $list {
|
16
|
+
|
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
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
@return $result;
|
30
|
+
}
|
@@ -0,0 +1,23 @@
|
|
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
|
+
*/
|
21
|
+
@function remove-nth($list, $index) {
|
22
|
+
@return replace-nth($list, $index, "");
|
23
|
+
}
|
@@ -0,0 +1,19 @@
|
|
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
|
+
*/
|
17
|
+
@function remove($list, $value, $recursive: false) {
|
18
|
+
@return replace($list, $value, "", $recursive);
|
19
|
+
}
|
@@ -0,0 +1,50 @@
|
|
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
|
+
*/
|
22
|
+
@function replace-nth($list, $index, $value) {
|
23
|
+
$result: false;
|
24
|
+
|
25
|
+
@if type-of($index) != number {
|
26
|
+
@warn "$index: #{quote($index)} is not a number for `replace-nth`/`remove-nth`.";
|
27
|
+
@return $result;
|
28
|
+
}
|
29
|
+
|
30
|
+
@else if $index == 0 {
|
31
|
+
@warn "List index 0 must be a non-zero integer for `replace-nth`/`remove-nth`.";
|
32
|
+
@return $result;
|
33
|
+
}
|
34
|
+
|
35
|
+
@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
|
+
@return $result;
|
38
|
+
}
|
39
|
+
|
40
|
+
@else {
|
41
|
+
$result: ();
|
42
|
+
$index: if($index < 0, length($list) + $index + 1, $index);
|
43
|
+
|
44
|
+
@for $i from 1 through length($list) {
|
45
|
+
$result: append($result, if($i == $index, $value, nth($list, $i)));
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
@return purge($result);
|
50
|
+
}
|
@@ -0,0 +1,32 @@
|
|
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
|
+
*/
|
18
|
+
@function replace($list, $old-value, $new-value, $recursive: false) {
|
19
|
+
$result: ();
|
20
|
+
|
21
|
+
@each $item in $list {
|
22
|
+
@if length($item) > 1 and $recursive {
|
23
|
+
$result: append($result, replace($item, $old-value, $new-value, $recursive));
|
24
|
+
}
|
25
|
+
|
26
|
+
@else {
|
27
|
+
$result: append($result, if($item == $old-value, $new-value, $item));
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
@return purge($result);
|
32
|
+
}
|
@@ -0,0 +1,30 @@
|
|
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
|
+
*/
|
14
|
+
@function reverse($list, $recursive: false) {
|
15
|
+
$result: ();
|
16
|
+
|
17
|
+
@for $i from length($list) * -1 through -1 {
|
18
|
+
$item: nth($list, abs($i));
|
19
|
+
|
20
|
+
@if length($item) > 1 and $recursive {
|
21
|
+
$result: append($result, reverse($item, $recursive));
|
22
|
+
}
|
23
|
+
|
24
|
+
@else {
|
25
|
+
$result: append($result, $item);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
@return $result;
|
30
|
+
}
|
@@ -0,0 +1,60 @@
|
|
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
|
+
*/
|
23
|
+
@function slice($list, $start: 1, $end: length($list)) {
|
24
|
+
$result: false;
|
25
|
+
|
26
|
+
@if type-of($start) != number or type-of($end) != number {
|
27
|
+
@warn "Either $start or $end are not a number for `slice`.";
|
28
|
+
@return $result;
|
29
|
+
}
|
30
|
+
|
31
|
+
@else if $start > $end {
|
32
|
+
@warn "The start index has to be lesser than or equals to the end index for `slice`.";
|
33
|
+
@return $result;
|
34
|
+
}
|
35
|
+
|
36
|
+
@else if $start < 1 or $end < 1 {
|
37
|
+
@warn "List indexes must be non-zero integers for `slice`.";
|
38
|
+
@return $result;
|
39
|
+
}
|
40
|
+
|
41
|
+
@else if $start > length($list) {
|
42
|
+
@warn "List index is #{$start} but list is only #{length($list)} item long for `slice`.";
|
43
|
+
@return $result;
|
44
|
+
}
|
45
|
+
|
46
|
+
@else if $end > length($list) {
|
47
|
+
@warn "List index is #{$end} but list is only #{length($list)} item long for `slice`.";
|
48
|
+
@return $result;
|
49
|
+
}
|
50
|
+
|
51
|
+
@else {
|
52
|
+
$result: ();
|
53
|
+
|
54
|
+
@for $i from $start through $end {
|
55
|
+
$result: append($result, nth($list, $i));
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
@return $result;
|
60
|
+
}
|
@@ -0,0 +1,42 @@
|
|
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
|
+
* @return [List]
|
14
|
+
*/
|
15
|
+
@function sort($list) {
|
16
|
+
$result : nth($list, 1);
|
17
|
+
|
18
|
+
@if length($list) > 1 {
|
19
|
+
@for $i from 2 through length($list) {
|
20
|
+
$item: nth($list, $i);
|
21
|
+
@if type-of($item) == number and unitless($item) {
|
22
|
+
@if $item > last($result) {
|
23
|
+
$result: append($result, $item);
|
24
|
+
}
|
25
|
+
@else {
|
26
|
+
$index: 0;
|
27
|
+
@for $i from 1 through length($result) {
|
28
|
+
@if $item <= nth($result, $i) {
|
29
|
+
$index: $i;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
$result: insert-nth($result, $index, $item);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
@else {
|
36
|
+
@warn "Not unitless number found. Omitted.";
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
@return $result;
|
42
|
+
}
|
@@ -0,0 +1,32 @@
|
|
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
|
+
*/
|
14
|
+
@function sum($list, $force: false) {
|
15
|
+
$result: 0;
|
16
|
+
|
17
|
+
@each $item in $list {
|
18
|
+
@if type-of($item) == number {
|
19
|
+
|
20
|
+
@if $force and unit($item) {
|
21
|
+
$item: $item / ($item * 0 + 1);
|
22
|
+
}
|
23
|
+
|
24
|
+
@if unitless($item) {
|
25
|
+
$result: $result + $item;
|
26
|
+
}
|
27
|
+
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
@return $result;
|
32
|
+
}
|
@@ -0,0 +1,29 @@
|
|
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 $is-nested [Boolean] : strictly internal boolean for recursivity
|
11
|
+
* -------------------------------------------------------------------------------
|
12
|
+
* @return [String]
|
13
|
+
*/
|
14
|
+
@function to-string($list, $glue: '', $is-nested: false) {
|
15
|
+
$result: null;
|
16
|
+
|
17
|
+
@each $item in $list {
|
18
|
+
@if length($item) > 1 {
|
19
|
+
$result: $result#{to-string($item, $glue, true)};
|
20
|
+
}
|
21
|
+
|
22
|
+
@else {
|
23
|
+
$condition: index($list, item) != length($list) or $is-nested;
|
24
|
+
$result: if($condition, $result#{$item}#{$glue}, $result#{$item});
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
@return $result;
|
29
|
+
}
|
@@ -0,0 +1,94 @@
|
|
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
|
+
* remove($list, $value, $recursive: false)
|
39
|
+
* Remove value(s) $value from $list
|
40
|
+
*
|
41
|
+
* remove-duplicates($list, $recursive: false)
|
42
|
+
* Remove duplicate values from $list
|
43
|
+
*
|
44
|
+
* remove-nth($list, $index)
|
45
|
+
* Remove value from $list at index $index
|
46
|
+
*
|
47
|
+
* replace($list, $old-value, $new-value, $recursive: false)
|
48
|
+
* Replace $old-value by $new-value in $list
|
49
|
+
*
|
50
|
+
* replace-nth($list, $index, $value)
|
51
|
+
* Replace value at $index from $list by $value
|
52
|
+
*
|
53
|
+
* reverse($list, $recursive: false)
|
54
|
+
* Reverse the order of $list
|
55
|
+
*
|
56
|
+
* slice($list, $start: 1, $end: length($list))
|
57
|
+
* Slice $list between $start and $end
|
58
|
+
*
|
59
|
+
* sort($list)
|
60
|
+
* Sort all numeric values in $list
|
61
|
+
*
|
62
|
+
* sum($list, $force: false)
|
63
|
+
* Sum up all unitless values in $list
|
64
|
+
*
|
65
|
+
* to-string($list, $glue: '', $is-nested: false)
|
66
|
+
* Join all elements of $list with $glue
|
67
|
+
*
|
68
|
+
* ------------------------------------------------------------------------------- *
|
69
|
+
* CodePen (SCSS): http://codepen.io/HugoGiraudel/pen/loAgq
|
70
|
+
* CodePen (Sass): http://codepen.io/HugoGiraudel/pen/BskrE
|
71
|
+
* Repository: https://github.com/Team-Sass/Sass-list-functions/
|
72
|
+
* ------------------------------------------------------------------------------- */
|
73
|
+
|
74
|
+
@import "SassyLists/chunk";
|
75
|
+
@import "SassyLists/count-values";
|
76
|
+
@import "SassyLists/debug";
|
77
|
+
@import "SassyLists/first";
|
78
|
+
@import "SassyLists/insert-nth";
|
79
|
+
@import "SassyLists/is-symmetrical";
|
80
|
+
@import "SassyLists/last";
|
81
|
+
@import "SassyLists/last-index";
|
82
|
+
@import "SassyLists/loop";
|
83
|
+
@import "SassyLists/prepend";
|
84
|
+
@import "SassyLists/purge";
|
85
|
+
@import "SassyLists/remove";
|
86
|
+
@import "SassyLists/remove-duplicates";
|
87
|
+
@import "SassyLists/remove-nth";
|
88
|
+
@import "SassyLists/replace";
|
89
|
+
@import "SassyLists/replace-nth";
|
90
|
+
@import "SassyLists/reverse";
|
91
|
+
@import "SassyLists/slice";
|
92
|
+
@import "SassyLists/sort";
|
93
|
+
@import "SassyLists/sum";
|
94
|
+
@import "SassyLists/to-string";
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SassyLists
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hugo Giraudel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sass
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: compass
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.12.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.12.1
|
46
|
+
description: Advanced Sass list functions
|
47
|
+
email:
|
48
|
+
- hugo.giraudel@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- readme.md
|
54
|
+
- lib/SassyLists.rb
|
55
|
+
- stylesheets/SassyLists/_chunk.scss
|
56
|
+
- stylesheets/SassyLists/_count-values.scss
|
57
|
+
- stylesheets/SassyLists/_debug.scss
|
58
|
+
- stylesheets/SassyLists/_first.scss
|
59
|
+
- stylesheets/SassyLists/_insert-nth.scss
|
60
|
+
- stylesheets/SassyLists/_is-symmetrical.scss
|
61
|
+
- stylesheets/SassyLists/_last-index.scss
|
62
|
+
- stylesheets/SassyLists/_last.scss
|
63
|
+
- stylesheets/SassyLists/_loop.scss
|
64
|
+
- stylesheets/SassyLists/_prepend.scss
|
65
|
+
- stylesheets/SassyLists/_purge.scss
|
66
|
+
- stylesheets/SassyLists/_remove-duplicates.scss
|
67
|
+
- stylesheets/SassyLists/_remove-nth.scss
|
68
|
+
- stylesheets/SassyLists/_remove.scss
|
69
|
+
- stylesheets/SassyLists/_replace-nth.scss
|
70
|
+
- stylesheets/SassyLists/_replace.scss
|
71
|
+
- stylesheets/SassyLists/_reverse.scss
|
72
|
+
- stylesheets/SassyLists/_slice.scss
|
73
|
+
- stylesheets/SassyLists/_sort.scss
|
74
|
+
- stylesheets/SassyLists/_sum.scss
|
75
|
+
- stylesheets/SassyLists/_to-string.scss
|
76
|
+
- stylesheets/_SassyLists.scss
|
77
|
+
homepage: https://github.com/Team-Sass/Sass-list-functions
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.3.6
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project: SassyLists
|
97
|
+
rubygems_version: 1.8.24
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: A collection of powerful Sass (SCSS) functions to deal with your lists.
|
101
|
+
test_files: []
|