sass-aleksi 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +44 -0
- data/lib/sass-aleksi.rb +31 -0
- data/stylesheets/_aleksi.scss +23 -0
- data/stylesheets/aleksi/_colors.scss +0 -0
- data/stylesheets/aleksi/_config.scss +11 -0
- data/stylesheets/aleksi/_general.scss +11 -0
- data/stylesheets/aleksi/_lengths.scss +8 -0
- data/stylesheets/aleksi/_lists.scss +16 -0
- data/stylesheets/aleksi/_maps.scss +21 -0
- data/stylesheets/aleksi/_math.scss +10 -0
- data/stylesheets/aleksi/_sides.scss +11 -0
- data/stylesheets/aleksi/config/_constants.scss +73 -0
- data/stylesheets/aleksi/general/_apply.scss +42 -0
- data/stylesheets/aleksi/general/_css-rule.scss +88 -0
- data/stylesheets/aleksi/general/_default-to.scss +35 -0
- data/stylesheets/aleksi/general/_is-of-type.scss +72 -0
- data/stylesheets/aleksi/general/_throw.scss +125 -0
- data/stylesheets/aleksi/lengths/_convert.scss +100 -0
- data/stylesheets/aleksi/lengths/_strip-unit.scss +37 -0
- data/stylesheets/aleksi/lists/_contained-in.scss +34 -0
- data/stylesheets/aleksi/lists/_depth.scss +46 -0
- data/stylesheets/aleksi/lists/_get-nth.scss +44 -0
- data/stylesheets/aleksi/lists/_is-list.scss +35 -0
- data/stylesheets/aleksi/lists/_list-filter.scss +48 -0
- data/stylesheets/aleksi/lists/_next.scss +47 -0
- data/stylesheets/aleksi/lists/_prepend.scss +40 -0
- data/stylesheets/aleksi/lists/_previous.scss +47 -0
- data/stylesheets/aleksi/lists/_set-list-separator.scss +173 -0
- data/stylesheets/aleksi/lists/_walk.scss +96 -0
- data/stylesheets/aleksi/lists/_wrap-in-list.scss +42 -0
- data/stylesheets/aleksi/maps/_debug-map.scss +39 -0
- data/stylesheets/aleksi/maps/_is-map.scss +31 -0
- data/stylesheets/aleksi/maps/_map-clean.scss +45 -0
- data/stylesheets/aleksi/maps/_map-depth.scss +46 -0
- data/stylesheets/aleksi/maps/_map-extend.scss +50 -0
- data/stylesheets/aleksi/maps/_map-filter.scss +84 -0
- data/stylesheets/aleksi/maps/_map-find.scss +95 -0
- data/stylesheets/aleksi/maps/_map-get-tuple.scss +33 -0
- data/stylesheets/aleksi/maps/_map-has-keys.scss +92 -0
- data/stylesheets/aleksi/maps/_map-merge-deep.scss +54 -0
- data/stylesheets/aleksi/maps/_map-select.scss +56 -0
- data/stylesheets/aleksi/maps/_map-sort.scss +125 -0
- data/stylesheets/aleksi/maps/_map-unique.scss +46 -0
- data/stylesheets/aleksi/maps/_map-walk.scss +79 -0
- data/stylesheets/aleksi/maps/_map-zip.scss +64 -0
- data/stylesheets/aleksi/math/_add.scss +66 -0
- data/stylesheets/aleksi/math/_divide.scss +66 -0
- data/stylesheets/aleksi/math/_multiply.scss +66 -0
- data/stylesheets/aleksi/math/_subtract.scss +66 -0
- data/stylesheets/aleksi/sides/_output-sides.scss +71 -0
- data/stylesheets/aleksi/sides/_reduce-sides.scss +74 -0
- data/stylesheets/aleksi/sides/_side-name.scss +48 -0
- data/stylesheets/aleksi/sides/_side-value.scss +83 -0
- data/stylesheets/aleksi/sides/_sides-shorthand.scss +64 -0
- data/stylesheets/aleksi/sides/_to-sides-list.scss +63 -0
- data/stylesheets/aleksi/sides/_to-sides-map.scss +57 -0
- metadata +199 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - CONVERT-LENGTH
|
3
|
+
// =============================================================================
|
4
|
+
//// @group aleksi-lengths
|
5
|
+
//// @author [Chris Eppstein](http://chriseppstein.github.io/)
|
6
|
+
|
7
|
+
// Base font size in pixels, if not already defined.
|
8
|
+
// Should be the same as the font-size of the html element.
|
9
|
+
$base-font-size: 16px !default;
|
10
|
+
|
11
|
+
// =convert-length( $length, $to-unit[, $from-context, $to-context ])
|
12
|
+
// -----------------------------------------------------------------------------
|
13
|
+
/// Convert any CSS <length> or <percentage> value to any another.
|
14
|
+
///
|
15
|
+
/// @param {number} $length - A css <length> or <percentage> value
|
16
|
+
/// @param {string} $to-unit - A css unit keyword, e.g. 'em', '%', 'px', etc.
|
17
|
+
/// @param {number} $from-context [$base-font-size] - The absolute length (in px) to which `$length` refers
|
18
|
+
/// @param {number} $to-context [$from-context] - the absolute length in px to which the output value will refer.
|
19
|
+
///
|
20
|
+
/// @return {type|...} - Description
|
21
|
+
/// @throw Description
|
22
|
+
///
|
23
|
+
/// @access public
|
24
|
+
/// @since 0.1.0
|
25
|
+
|
26
|
+
@function convert-length(
|
27
|
+
$length,
|
28
|
+
$to-unit,
|
29
|
+
$from-context: $base-font-size,
|
30
|
+
$to-context: $from-context
|
31
|
+
) {
|
32
|
+
$from-unit: unit($length);
|
33
|
+
|
34
|
+
// Optimize for cases where `from` and `to` units are accidentally the same.
|
35
|
+
@if $from-unit == $to-unit { @return $length; }
|
36
|
+
|
37
|
+
// Context values must be in px so we can determine a conversion ratio for
|
38
|
+
// relative units.
|
39
|
+
@if unit($from-context) != 'px' { @warn "Paremeter $from-context must resolve to a value in pixel units."; }
|
40
|
+
@if unit($to-context) != 'px' { @warn "Parameter $to-context must resolve to a value in pixel units."; }
|
41
|
+
|
42
|
+
// Convert input length to pixels
|
43
|
+
$px-length: $length;
|
44
|
+
|
45
|
+
@if $from-unit != 'px' {
|
46
|
+
// Convert relative units using the from-context parameter.
|
47
|
+
@if $from-unit == 'em' { $px-length: $length * $from-context / 1em }
|
48
|
+
@else if $from-unit == 'rem' { $px-length: $length * $base-font-size / 1rem }
|
49
|
+
@else if $from-unit == '%' { $px-length: $length * $from-context / 100% }
|
50
|
+
@else if $from-unit == 'ex' { $px-length: $length * $from-context / 2ex }
|
51
|
+
// Convert absolute units using Sass' conversion table.
|
52
|
+
@else if $from-unit == 'in' or
|
53
|
+
$from-unit == 'mm' or
|
54
|
+
$from-unit == 'cm' or
|
55
|
+
$from-unit == 'pt' or
|
56
|
+
$from-unit == 'pc' { $px-length: 0px + $length }
|
57
|
+
// Certain units can't be converted.
|
58
|
+
@else if $from-unit == 'ch' or
|
59
|
+
$from-unit == 'vw' or
|
60
|
+
$from-unit == 'vh' or
|
61
|
+
$from-unit == 'vmin' {
|
62
|
+
@warn "#{$from-unit} units can't be reliably converted; Returning original value.";
|
63
|
+
@return $length;
|
64
|
+
}
|
65
|
+
@else {
|
66
|
+
@warn "#{$from-unit} is an unknown length unit. Returning original value.";
|
67
|
+
@return $length;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
// Convert length in pixels to the output unit
|
72
|
+
$output-length: $px-length;
|
73
|
+
@if $to-unit != 'px' {
|
74
|
+
// Relative units
|
75
|
+
@if $to-unit == 'em' { $output-length: $px-length * 1em / $to-context }
|
76
|
+
@else if $to-unit == 'rem' { $output-length: $px-length * 1rem / $base-font-size }
|
77
|
+
@else if $to-unit == '%' { $output-length: $px-length * 100% / $to-context }
|
78
|
+
@else if $to-unit == 'ex' { $output-length: $px-length * 2ex / $to-context }
|
79
|
+
// Absolute units
|
80
|
+
@else if $to-unit == 'in' { $output-length: 0in + $px-length }
|
81
|
+
@else if $to-unit == 'mm' { $output-length: 0mm + $px-length }
|
82
|
+
@else if $to-unit == 'cm' { $output-length: 0cm + $px-length }
|
83
|
+
@else if $to-unit == 'pt' { $output-length: 0pt + $px-length }
|
84
|
+
@else if $to-unit == 'pc' { $output-length: 0pc + $px-length }
|
85
|
+
// Non-convertible units
|
86
|
+
@else if $to-unit == 'ch' or
|
87
|
+
$to-unit == 'vw' or
|
88
|
+
$to-unit == 'vh' or
|
89
|
+
$to-unit == 'vmin' {
|
90
|
+
@warn "#{$to-unit} units can't be reliably converted; Returning original value.";
|
91
|
+
@return $length;
|
92
|
+
}
|
93
|
+
@else {
|
94
|
+
@warn "#{$to-unit} is an unknown length unit. Returning original value.";
|
95
|
+
@return $length;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
@return $output-length;
|
100
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - STRIP-UNIT
|
3
|
+
// =============================================================================
|
4
|
+
//// @group aleksi-units
|
5
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
6
|
+
|
7
|
+
// =strip-unit( $number )
|
8
|
+
// -----------------------------------------------------------------------------
|
9
|
+
/// Removes the unit of a given number.
|
10
|
+
/// @author [Hugo Giraudel](http://hugogiraudel.com)
|
11
|
+
///
|
12
|
+
/// @param {number} $number - Number from which to strip the unit.
|
13
|
+
///
|
14
|
+
/// @return {number} - Unitless `$number`.
|
15
|
+
/// @throw Error if `$number` is not a number.
|
16
|
+
///
|
17
|
+
/// @example scss
|
18
|
+
/// $foo: strip-unit(10px);
|
19
|
+
/// // => 10
|
20
|
+
/// $bar: strip-unit(1.5em);
|
21
|
+
/// // => 1.5
|
22
|
+
/// $baz: strip-unit(50%);
|
23
|
+
/// // => 50
|
24
|
+
///
|
25
|
+
/// @access public
|
26
|
+
/// @since 0.1.0
|
27
|
+
///
|
28
|
+
/// @todo Unit test the 'strip-unit' function
|
29
|
+
|
30
|
+
@function strip-unit($number)
|
31
|
+
{
|
32
|
+
@if type-of($number) != number {
|
33
|
+
@return throw-error("strip-unit():: $number must be a number. Was #{inspect($number)}.");
|
34
|
+
}
|
35
|
+
|
36
|
+
@return $number / ($number * 0 + 1);
|
37
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - IS-CONTAINED
|
3
|
+
// =============================================================================
|
4
|
+
|
5
|
+
// =contained-in( $value, $list )
|
6
|
+
// -----------------------------------------------------------------------------
|
7
|
+
/// Checks if the given value is contained in a list. Behaves like `sl-contain`,
|
8
|
+
/// but with the value as first argument. Useful to check for specific values
|
9
|
+
/// when walking over a list or map.
|
10
|
+
///
|
11
|
+
/// @param {type|...} $name [default] - Description
|
12
|
+
///
|
13
|
+
/// @return {type|...} - Description
|
14
|
+
/// @throw Description
|
15
|
+
///
|
16
|
+
/// @example scss
|
17
|
+
/// $foo: contained-in(10px 'foo', 10px);
|
18
|
+
/// // => true
|
19
|
+
/// $bar: contained-in(10px 'foo', 'bar');
|
20
|
+
/// // => false
|
21
|
+
/// $baz: sl-every('a' 'b' 'c' 'd', 'contained-in', 'a' 'b' 'c');
|
22
|
+
/// // => false
|
23
|
+
/// $wiz: sl-every('a' 'b' 'c', 'contained-in', 'a' 'b' 'c');
|
24
|
+
/// // => true
|
25
|
+
///
|
26
|
+
/// @access public
|
27
|
+
/// @since version
|
28
|
+
///
|
29
|
+
/// @todo Test the 'contained-in' function
|
30
|
+
|
31
|
+
@function contained-in( $value, $list )
|
32
|
+
{
|
33
|
+
@return (index($list, $value) != null);
|
34
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - DEPTH
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/maps/map-depth";
|
9
|
+
|
10
|
+
// =depth( $list )
|
11
|
+
// -----------------------------------------------------------------------------
|
12
|
+
/// Returns the depth level of a list. If a single value is passed, it will
|
13
|
+
/// return 1.
|
14
|
+
/// **Note**: also accepts maps, which delegates to `map-depth()`.
|
15
|
+
///
|
16
|
+
/// @param {list|map} $list - The list to analyze.
|
17
|
+
///
|
18
|
+
/// @return {number} - The depth of `$list`.
|
19
|
+
///
|
20
|
+
/// @example scss
|
21
|
+
/// $foo: depth(10 true 'foo' ('bar' 'baz') );
|
22
|
+
/// // => 2
|
23
|
+
/// $bar: depth(10 true 'foo');
|
24
|
+
/// // => 1
|
25
|
+
/// $baz: depth('foo');
|
26
|
+
/// // => 1
|
27
|
+
///
|
28
|
+
/// @access public
|
29
|
+
/// @since 0.1.0
|
30
|
+
|
31
|
+
@function depth( $list )
|
32
|
+
{
|
33
|
+
@if type-of($list) == 'map' {
|
34
|
+
@return map-depth($list);
|
35
|
+
}
|
36
|
+
|
37
|
+
$lvl: 1;
|
38
|
+
|
39
|
+
@each $item in $list {
|
40
|
+
@if type-of($item) == 'list' {
|
41
|
+
$lvl: max(depth($item) + 1, $lvl);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
@return $lvl;
|
46
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - GET-NTH
|
3
|
+
// =============================================================================
|
4
|
+
|
5
|
+
// =get-nth( $list, $index )
|
6
|
+
// -----------------------------------------------------------------------------
|
7
|
+
/// Retreives the item at a given index in a list. Differs from Sass's native
|
8
|
+
/// `nth` function by returning `null` if the index is out of scope instead of
|
9
|
+
/// throwing an error. In this way it behaves more like `map-get()`.
|
10
|
+
///
|
11
|
+
/// @param {list} $list - The list from which to retreive an item.
|
12
|
+
/// @param {number} $index - The index of the item to retreive
|
13
|
+
///
|
14
|
+
/// @return {any} - The item found at $index in $list, or `null` if none was found.
|
15
|
+
///
|
16
|
+
/// @example scss
|
17
|
+
/// $foo: get-nth(10px 'foo' false, 2);
|
18
|
+
/// // => 'foo'
|
19
|
+
/// $bar: get-nth(10px 'foo' false, 4);
|
20
|
+
/// // => null
|
21
|
+
///
|
22
|
+
/// @access public
|
23
|
+
/// @since 01.0
|
24
|
+
|
25
|
+
@function get-nth( $list, $index )
|
26
|
+
{
|
27
|
+
@if $index <= length($list) {
|
28
|
+
@return nth($list, $index);
|
29
|
+
}
|
30
|
+
|
31
|
+
@return null;
|
32
|
+
}
|
33
|
+
|
34
|
+
// =list-get( $list, $index )
|
35
|
+
// -----------------------------------------------------------------------------
|
36
|
+
/// @alias get-nth
|
37
|
+
///
|
38
|
+
/// @acces public
|
39
|
+
/// @since 0.1.0
|
40
|
+
|
41
|
+
@function list-get( $list, $index )
|
42
|
+
{
|
43
|
+
@return get-nth($list, $index);
|
44
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - IS-LIST
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
// =is-list( $value )
|
9
|
+
// -----------------------------------------------------------------------------
|
10
|
+
/// Checks whether the given value is a number. Also accepts argument lists,
|
11
|
+
/// contrary to manually testing `type-of($args) == list`.
|
12
|
+
///
|
13
|
+
/// @param {any} $value - The value to test.
|
14
|
+
///
|
15
|
+
/// @return {bool} - Whether `$value` is a list.
|
16
|
+
///
|
17
|
+
/// @example scss
|
18
|
+
/// $foo: is-list(10 true 'foo');
|
19
|
+
/// // => true
|
20
|
+
///
|
21
|
+
/// @example scss - Testing an arglist
|
22
|
+
/// @function arglist-is-list($args...) {
|
23
|
+
/// @return is-list($args);
|
24
|
+
/// }
|
25
|
+
/// $foo: arglist-is-list(10, true, 'foo');
|
26
|
+
/// // => true
|
27
|
+
/// $bar: arglist-is-list(10);
|
28
|
+
/// // => true
|
29
|
+
///
|
30
|
+
/// @access public
|
31
|
+
/// @since 0.1.0
|
32
|
+
|
33
|
+
@function is-list( $value ) {
|
34
|
+
@return (type-of($value) == 'list' or type-of($value) == 'arglist');
|
35
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - FILTER
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/maps/map-filter";
|
9
|
+
|
10
|
+
// =list-filter( $list, $test[, $args... ])
|
11
|
+
// -----------------------------------------------------------------------------
|
12
|
+
/// Removes items in a list that don't pass the given test function. The current
|
13
|
+
/// list item will be passed as first argument to the test function.
|
14
|
+
/// **Note**: to pass the test, the test function must return a truethy value —
|
15
|
+
/// not per se the boolean `true`.
|
16
|
+
///
|
17
|
+
/// @param {list|map} $list - The list of items to test.
|
18
|
+
/// @param {string} $test - The name of the test function to run on each item.
|
19
|
+
/// @param {arglist} $args... - Additional arguments for `$test`.
|
20
|
+
///
|
21
|
+
/// @return {list} - `$list` without the items that didn't pass the `$test` function.
|
22
|
+
///
|
23
|
+
/// @example scss
|
24
|
+
/// $foo: list-filter( 10 5px 7 3, 'unitless');
|
25
|
+
/// // => 10 7 3
|
26
|
+
/// $bar: list-filter( 10px 2.5 4px 8em, 'comparable', 1px);
|
27
|
+
/// // => 10px 2.5 4px
|
28
|
+
///
|
29
|
+
/// @access public
|
30
|
+
/// @since 0.1.0
|
31
|
+
|
32
|
+
@function list-filter( $list, $test, $args... )
|
33
|
+
{
|
34
|
+
// delegate to 'map-filter' if filtering a map
|
35
|
+
@if type-of($list) == 'map' {
|
36
|
+
@return map-filter($list, $test, $args...);
|
37
|
+
}
|
38
|
+
|
39
|
+
$res: ();
|
40
|
+
|
41
|
+
@each $item in $list {
|
42
|
+
@if call($test, $item, $args...) {
|
43
|
+
$res: append($res, $item);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
@return $res;
|
48
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - NEXT
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/general/throw";
|
9
|
+
|
10
|
+
// =next( $list, $value )
|
11
|
+
// -----------------------------------------------------------------------------
|
12
|
+
/// Returns the item sitting next to the given value in alist. If the value is
|
13
|
+
/// found multiple times, it will use the first one. If the value was not found
|
14
|
+
/// or is in last position in the list, it will return `null`.
|
15
|
+
///
|
16
|
+
/// @param {list} $list - The list in which to search.
|
17
|
+
/// @param {list} $value - The value to search in `$list`.
|
18
|
+
///
|
19
|
+
/// @return {any} - The value sitting previous to `$value` in `$list`.
|
20
|
+
/// @throw Warning if `$value` was not found in `$list`.
|
21
|
+
/// @throw Warning if `$value` is the last value in `$list`.
|
22
|
+
///
|
23
|
+
/// @example scss
|
24
|
+
/// $foo: next( 'foo' 'bar' 'baz', 'bar');
|
25
|
+
/// // => 'baz'
|
26
|
+
/// $bar: next( 'foo' 'bar' 'baz', 'baz');
|
27
|
+
/// // => null
|
28
|
+
/// $baz: next( 'foo' 'bar' 'baz', 'wiz');
|
29
|
+
/// // => null
|
30
|
+
///
|
31
|
+
/// @access public
|
32
|
+
/// @since 0.1.0
|
33
|
+
|
34
|
+
@function next( $list, $value )
|
35
|
+
{
|
36
|
+
$index: index($list, $value);
|
37
|
+
|
38
|
+
@if $index == null {
|
39
|
+
@return throw-warning('next():: #{inspect($value)} could not be found in #{inspect($list)}.');
|
40
|
+
}
|
41
|
+
|
42
|
+
@else if $index == length($list) {
|
43
|
+
@return throw-warning('next():: #{inspect($value)} is the last item in #{inspect($list)}.');
|
44
|
+
}
|
45
|
+
|
46
|
+
@return nth($list, $index + 1);
|
47
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALESKI - PREPEND
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
// =prepend( $list, $value[, $separator ])
|
9
|
+
// -----------------------------------------------------------------------------
|
10
|
+
/// A simple function to prepend an item to any other value.
|
11
|
+
/// **Note**: SassyLists provides a similar 'sl-prepend()' function, but passing
|
12
|
+
/// it a list or a map will return a flattened list instead of nested.
|
13
|
+
/// Aleksi's `prepend()` function will instead behave like sass's native
|
14
|
+
/// `append()` function by nesting lists and maps (unless the $separator
|
15
|
+
/// argument suggests otherwise).
|
16
|
+
///
|
17
|
+
/// @param {list} $list - The list to which $value shoudl be prepended.
|
18
|
+
/// @param {list} $value - The value to prepend to $list.
|
19
|
+
/// @param {string} $separator (list-separator($list))- The list separator to use when prepending.
|
20
|
+
///
|
21
|
+
/// @return {list} - A copy of $list, with $value added in first position.
|
22
|
+
/// @throw Error if $separator is neither 'space' nor 'comma'.
|
23
|
+
///
|
24
|
+
/// @example scss
|
25
|
+
/// $foo: prepend('bar', 5);
|
26
|
+
/// // => 5 'bar'
|
27
|
+
/// $bar: prepend( 10 false 'baz', null 'wiz');
|
28
|
+
/// // => 'baz' null 'wiz' 10 false;
|
29
|
+
/// $baz: prepend( 10 false 'baz', ('en': 'hello', 'es': 'ola'));
|
30
|
+
/// // => ('en': 'hello', 'es': 'ola') 10 false 'baz';
|
31
|
+
/// $wiz: prepend( (10, false, 'baz'), ('en': 'hello', 'es': 'ola'));
|
32
|
+
/// // => ('en': 'hello', 'es': 'ola'), 10, false, 'baz';
|
33
|
+
///
|
34
|
+
/// @access public
|
35
|
+
/// @since 0.1.0
|
36
|
+
|
37
|
+
@function prepend( $list, $value, $separator: list-separator($list) )
|
38
|
+
{
|
39
|
+
@return append($value, $list, $separator);
|
40
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - PREVIOUS
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/general/throw";
|
9
|
+
|
10
|
+
// =previous( $list, $value )
|
11
|
+
// -----------------------------------------------------------------------------
|
12
|
+
/// Returns the item sitting previous to the given value in alist. If the value
|
13
|
+
/// is found multiple times, it will use the first one. If the value was not
|
14
|
+
/// found or is in first position in the list, it will return `null`.
|
15
|
+
///
|
16
|
+
/// @param {list} $list - The list in which to search.
|
17
|
+
/// @param {list} $value - The value to search in `$list`.
|
18
|
+
///
|
19
|
+
/// @return {any} - The value sitting next to `$value` in `$list`.
|
20
|
+
/// @throw Warning if `$value` was not found in `$list`.
|
21
|
+
/// @throw Warning if `$value` is the first value in `$list`.
|
22
|
+
///
|
23
|
+
/// @example scss
|
24
|
+
/// $foo: next( 'foo' 'bar' 'baz', 'bar');
|
25
|
+
/// // => 'foo'
|
26
|
+
/// $bar: next( 'foo' 'bar' 'baz', 'foo');
|
27
|
+
/// // => null
|
28
|
+
/// $baz: next( 'foo' 'bar' 'baz', 'wiz');
|
29
|
+
/// // => null
|
30
|
+
///
|
31
|
+
/// @access public
|
32
|
+
/// @since 0.1.0
|
33
|
+
|
34
|
+
@function previous( $list, $value )
|
35
|
+
{
|
36
|
+
$index: index($list, $value);
|
37
|
+
|
38
|
+
@if $index == null {
|
39
|
+
@return throw-warning('previous():: #{inspect($value)} could not be found in #{inspect($list)}.');
|
40
|
+
}
|
41
|
+
|
42
|
+
@else if $index == 1 {
|
43
|
+
@return throw-warning('previous():: #{inspect($value)} is the first item in #{inspect($list)}.');
|
44
|
+
}
|
45
|
+
|
46
|
+
@return nth($list, $index - 1);
|
47
|
+
}
|
@@ -0,0 +1,173 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - SET-LIST-SEPARATOR
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
////
|
8
|
+
//// @todo Move 'shortcut' functions to separate files ?
|
9
|
+
|
10
|
+
@import "aleksi/general/throw";
|
11
|
+
@import "aleksi/lists/is-list";
|
12
|
+
|
13
|
+
// =set-list-separator( $list, $separator )
|
14
|
+
// -----------------------------------------------------------------------------
|
15
|
+
/// Converts a list to the given lists separator.
|
16
|
+
/// **Note**: Because maps can only use the comma separator a map is passed,
|
17
|
+
/// passing a map will throw a warning and return the map as is.
|
18
|
+
///
|
19
|
+
/// @param {list} $list - The list on which to set the separator.
|
20
|
+
/// @param {list} $separator - The separator to set on `$list`
|
21
|
+
///
|
22
|
+
/// @return {list} - The version of `$list` using the given separator
|
23
|
+
///
|
24
|
+
/// @example scss
|
25
|
+
/// $foo: set-list-separator( 10 true 'foo', 'space');
|
26
|
+
/// // => 10 true 'foo'
|
27
|
+
/// $bar: set-list-separator( 10 true 'foo', 'comma');
|
28
|
+
/// // => 10, true, 'foo'
|
29
|
+
/// $baz: set-list-separator( 10, 'comma');
|
30
|
+
/// // => (10,)
|
31
|
+
/// type-of($baz);
|
32
|
+
/// // => 'list'
|
33
|
+
/// list-separator($baz)
|
34
|
+
/// // => 'comma'
|
35
|
+
///
|
36
|
+
/// @access public
|
37
|
+
/// @since 0.1.0
|
38
|
+
|
39
|
+
@function set-list-separator( $list, $separator )
|
40
|
+
{
|
41
|
+
// optimization: return list that are already comma-separated as is
|
42
|
+
@if is-list($list) and list-separator($list) == $separator {
|
43
|
+
@return $list;
|
44
|
+
}
|
45
|
+
|
46
|
+
@else if type-of($list) == 'map' {
|
47
|
+
$e: throw-warning('set-list-separator():: Can not change the separator of a map.');
|
48
|
+
@return $list;
|
49
|
+
}
|
50
|
+
|
51
|
+
$res: ();
|
52
|
+
|
53
|
+
@each $item in $list {
|
54
|
+
$res: append($res, $item, $separator);
|
55
|
+
}
|
56
|
+
|
57
|
+
@return $res;
|
58
|
+
}
|
59
|
+
|
60
|
+
// =to-separator( $list, $separator )
|
61
|
+
// -----------------------------------------------------------------------------
|
62
|
+
/// @alias set-list-separator
|
63
|
+
///
|
64
|
+
/// @access public
|
65
|
+
/// @since 0.1.0
|
66
|
+
|
67
|
+
@function to-separator( $list, $separator )
|
68
|
+
{
|
69
|
+
@return set-list-separator( $list, $separator );
|
70
|
+
}
|
71
|
+
|
72
|
+
// =to-comma-list( $list )
|
73
|
+
// -----------------------------------------------------------------------------
|
74
|
+
/// Converts a list into a comma-separated list. If the list is already comma-
|
75
|
+
/// separated, then it will be returned as is.
|
76
|
+
///
|
77
|
+
/// @param {list} $list - The list to convert
|
78
|
+
///
|
79
|
+
/// @return {list} - The modified list with comma separation.
|
80
|
+
///
|
81
|
+
/// @example scss
|
82
|
+
/// $foo: to-comma-list( 10 true 'foo' );
|
83
|
+
/// // => 10, true, 'foo'
|
84
|
+
/// $bar: to-comma-list( (10, true, 'foo') );
|
85
|
+
/// // => 10, true, 'foo'
|
86
|
+
/// $baz: to-comma-list(10);
|
87
|
+
/// // => (10,)
|
88
|
+
/// type-of($baz);
|
89
|
+
/// // => 'list'
|
90
|
+
/// list-separator($baz)
|
91
|
+
/// // => 'comma'
|
92
|
+
///
|
93
|
+
/// @access public
|
94
|
+
/// @since 0.1.0
|
95
|
+
|
96
|
+
@function to-comma-list( $list )
|
97
|
+
{
|
98
|
+
@return set-list-separator($list, 'comma');
|
99
|
+
}
|
100
|
+
|
101
|
+
// =to-comma-list( $list )
|
102
|
+
// -----------------------------------------------------------------------------
|
103
|
+
/// Converts a list into a space-separated list. If the list is already space-
|
104
|
+
/// separated, then it will be returned as is.
|
105
|
+
///
|
106
|
+
/// @param {list} $list - The list to convert
|
107
|
+
///
|
108
|
+
/// @return {list} - The modified list with space separation.
|
109
|
+
///
|
110
|
+
/// @example scss
|
111
|
+
/// $foo: to-space-list( (10, true, 'foo') );
|
112
|
+
/// // => 10 true 'foo'
|
113
|
+
/// $bar: to-space-list( (10, true, 'foo') );
|
114
|
+
/// // => 10 true 'foo'
|
115
|
+
/// $baz: to-space-list(10);
|
116
|
+
/// // => (10)
|
117
|
+
/// type-of($baz);
|
118
|
+
/// // => 'list'
|
119
|
+
/// list-separator($baz)
|
120
|
+
/// // => 'space'
|
121
|
+
///
|
122
|
+
/// @access public
|
123
|
+
/// @since 0.1.0
|
124
|
+
|
125
|
+
@function to-space-list( $list )
|
126
|
+
{
|
127
|
+
@return set-list-separator($list, 'space');
|
128
|
+
}
|
129
|
+
|
130
|
+
// =switch-list-separator( $list )
|
131
|
+
// -----------------------------------------------------------------------------
|
132
|
+
/// Changes the separator of a given list, from 'space' to 'comma', and from
|
133
|
+
/// 'comma' to space.
|
134
|
+
/// **Note**: simple values are considered to be space-separated lists, as for
|
135
|
+
/// all native sass list functions.
|
136
|
+
/// **Note**: map values are considered to be comma-separated lists, as for
|
137
|
+
/// all native sass list functions.
|
138
|
+
///
|
139
|
+
/// @param {list} $list - The list on which to switch separator.
|
140
|
+
///
|
141
|
+
/// @return {list} - The space-separated version of `$list` if it is comma-separated, and vice-versa.
|
142
|
+
///
|
143
|
+
/// @example scss
|
144
|
+
/// $foo: switch-list-separator(10 true 'foo');
|
145
|
+
/// // => 10, true 'foo'
|
146
|
+
/// $bar: switch-list-separator((10, true, 'foo'));
|
147
|
+
/// // => 10 true 'foo'
|
148
|
+
/// $baz: switch-list-separator(false);
|
149
|
+
/// // => (false,)
|
150
|
+
/// type-of($baz);
|
151
|
+
/// // => 'list'
|
152
|
+
/// list-separator($baz)
|
153
|
+
/// // => 'comma'
|
154
|
+
///
|
155
|
+
/// @access public
|
156
|
+
/// @since 0.1.0
|
157
|
+
|
158
|
+
@function switch-list-separator( $list )
|
159
|
+
{
|
160
|
+
@return if(list-separator($list) == 'comma', to-space-list($list), to-comma-list($list));
|
161
|
+
}
|
162
|
+
|
163
|
+
// =switch-separator( $list )
|
164
|
+
// -----------------------------------------------------------------------------
|
165
|
+
/// @alias switch-list-separator
|
166
|
+
///
|
167
|
+
/// @access public
|
168
|
+
/// @since 0.1.0
|
169
|
+
|
170
|
+
@function switch-separator( $list )
|
171
|
+
{
|
172
|
+
@return switch-list-separator($list);
|
173
|
+
}
|