sass-aleksi 0.1.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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +44 -0
  3. data/lib/sass-aleksi.rb +31 -0
  4. data/stylesheets/_aleksi.scss +23 -0
  5. data/stylesheets/aleksi/_colors.scss +0 -0
  6. data/stylesheets/aleksi/_config.scss +11 -0
  7. data/stylesheets/aleksi/_general.scss +11 -0
  8. data/stylesheets/aleksi/_lengths.scss +8 -0
  9. data/stylesheets/aleksi/_lists.scss +16 -0
  10. data/stylesheets/aleksi/_maps.scss +21 -0
  11. data/stylesheets/aleksi/_math.scss +10 -0
  12. data/stylesheets/aleksi/_sides.scss +11 -0
  13. data/stylesheets/aleksi/config/_constants.scss +73 -0
  14. data/stylesheets/aleksi/general/_apply.scss +42 -0
  15. data/stylesheets/aleksi/general/_css-rule.scss +88 -0
  16. data/stylesheets/aleksi/general/_default-to.scss +35 -0
  17. data/stylesheets/aleksi/general/_is-of-type.scss +72 -0
  18. data/stylesheets/aleksi/general/_throw.scss +125 -0
  19. data/stylesheets/aleksi/lengths/_convert.scss +100 -0
  20. data/stylesheets/aleksi/lengths/_strip-unit.scss +37 -0
  21. data/stylesheets/aleksi/lists/_contained-in.scss +34 -0
  22. data/stylesheets/aleksi/lists/_depth.scss +46 -0
  23. data/stylesheets/aleksi/lists/_get-nth.scss +44 -0
  24. data/stylesheets/aleksi/lists/_is-list.scss +35 -0
  25. data/stylesheets/aleksi/lists/_list-filter.scss +48 -0
  26. data/stylesheets/aleksi/lists/_next.scss +47 -0
  27. data/stylesheets/aleksi/lists/_prepend.scss +40 -0
  28. data/stylesheets/aleksi/lists/_previous.scss +47 -0
  29. data/stylesheets/aleksi/lists/_set-list-separator.scss +173 -0
  30. data/stylesheets/aleksi/lists/_walk.scss +96 -0
  31. data/stylesheets/aleksi/lists/_wrap-in-list.scss +42 -0
  32. data/stylesheets/aleksi/maps/_debug-map.scss +39 -0
  33. data/stylesheets/aleksi/maps/_is-map.scss +31 -0
  34. data/stylesheets/aleksi/maps/_map-clean.scss +45 -0
  35. data/stylesheets/aleksi/maps/_map-depth.scss +46 -0
  36. data/stylesheets/aleksi/maps/_map-extend.scss +50 -0
  37. data/stylesheets/aleksi/maps/_map-filter.scss +84 -0
  38. data/stylesheets/aleksi/maps/_map-find.scss +95 -0
  39. data/stylesheets/aleksi/maps/_map-get-tuple.scss +33 -0
  40. data/stylesheets/aleksi/maps/_map-has-keys.scss +92 -0
  41. data/stylesheets/aleksi/maps/_map-merge-deep.scss +54 -0
  42. data/stylesheets/aleksi/maps/_map-select.scss +56 -0
  43. data/stylesheets/aleksi/maps/_map-sort.scss +125 -0
  44. data/stylesheets/aleksi/maps/_map-unique.scss +46 -0
  45. data/stylesheets/aleksi/maps/_map-walk.scss +79 -0
  46. data/stylesheets/aleksi/maps/_map-zip.scss +64 -0
  47. data/stylesheets/aleksi/math/_add.scss +66 -0
  48. data/stylesheets/aleksi/math/_divide.scss +66 -0
  49. data/stylesheets/aleksi/math/_multiply.scss +66 -0
  50. data/stylesheets/aleksi/math/_subtract.scss +66 -0
  51. data/stylesheets/aleksi/sides/_output-sides.scss +71 -0
  52. data/stylesheets/aleksi/sides/_reduce-sides.scss +74 -0
  53. data/stylesheets/aleksi/sides/_side-name.scss +48 -0
  54. data/stylesheets/aleksi/sides/_side-value.scss +83 -0
  55. data/stylesheets/aleksi/sides/_sides-shorthand.scss +64 -0
  56. data/stylesheets/aleksi/sides/_to-sides-list.scss +63 -0
  57. data/stylesheets/aleksi/sides/_to-sides-map.scss +57 -0
  58. metadata +199 -0
@@ -0,0 +1,66 @@
1
+ // =============================================================================
2
+ // =ALEKSI - SUBTRACT
3
+ // =============================================================================
4
+ ////
5
+ //// @group aleksi-math
6
+ //// @author [Yoannis Jamar](http://yoannis.me)
7
+
8
+ @import "SassyLists";
9
+ @import "aleksi/general/throw";
10
+ @import "aleksi/general/is-of-type";
11
+
12
+ // =subtract( $terms... )
13
+ // -----------------------------------------------------------------------------
14
+ /// Calculates the difference between two or more numbers. Usefull when relying
15
+ /// on `call()`, `walk()` or `apply()` for mathematical operations.
16
+ /// **Note**: passing more then 2 arguments will subtract them successively.
17
+ /// **Note**: if one of the terms is not a number, it will return `null`.
18
+ ///
19
+ /// @param {arglist} $terms... - The operators in the subtraction.
20
+ ///
21
+ /// @return {number|null} - The difference resulting from subtracting `$terms`.
22
+ /// @throw Warning if one of the terms is not a number.
23
+ ///
24
+ /// @example scss
25
+ /// $foo: subtract(10, 5);
26
+ /// // => 5
27
+ /// $bar: subtract(10, 'hello')
28
+ /// // => null
29
+ /// $baz: subtract(10 5, 3)
30
+ /// // => null
31
+ /// $wiz: subtract(10, 5, 3)
32
+ /// // => 2
33
+ ///
34
+ /// @access public
35
+ /// @since 0.1.0
36
+
37
+ @function subtract( $terms... )
38
+ {
39
+ @if not sl-every($terms, 'is-of-type', 'number') {
40
+ @return throw-warning('subtract():: all $terms must be numbers — returning null.');
41
+ }
42
+
43
+ @if length($terms) < 2 {
44
+ @return thow-error('subtract():: wrong number of arguments, 1 instead of 2 or more.');
45
+ }
46
+
47
+ $diff: nth($terms, 1);
48
+
49
+ @each $term in sl-slice($terms, 2) {
50
+ $diff: $diff - $term;
51
+ }
52
+
53
+ @return $diff;
54
+ }
55
+
56
+ // =diff( $terms... )
57
+ // -----------------------------------------------------------------------------
58
+ /// @alias subtract
59
+ ///
60
+ /// @access public
61
+ /// @since 0.1.0
62
+
63
+ @function diff( $terms... )
64
+ {
65
+ @return subtract($terms...);
66
+ }
@@ -0,0 +1,71 @@
1
+ // =============================================================================
2
+ // =ALEKSI - SIDE-PROPERTY
3
+ // =============================================================================
4
+
5
+ @import "aleksi/config";
6
+ @import "aleksi/general/css-rule";
7
+ @import "aleksi/sides/side-value";
8
+ @import "aleksi/sides/reduce-sides";
9
+
10
+ // =output-sides( $property, $values[, $important ])
11
+ // -----------------------------------------------------------------------------
12
+ /// Output a CSS property for a side-list value. The keyword 'offset' is
13
+ /// accepted to output the 'top', 'right', 'bottom' and 'left'.
14
+ ///
15
+ /// @param {property} $name - The CSS property name to output.
16
+ /// @param {list} $values - The sides-list describing the property's values.
17
+ /// @param {bool} $important [false] - Whether to add the '!imporant' flag.
18
+ ///
19
+ /// @example scss - SCSS stylesheet
20
+ /// .foo {
21
+ /// position: absolute;
22
+ /// @include output-sides('offset', 10px null null 10px);
23
+ /// @include output-sides('margin', 10px null 1em);
24
+ /// @include output-sides('padding', 0.5em 5%);
25
+ /// }
26
+ ///
27
+ /// @example css - CSS output
28
+ /// .foo {
29
+ /// position: absolute;
30
+ /// top: 10px;
31
+ /// left: 10px;
32
+ /// margin-top: 10px;
33
+ /// margin-bottom: 1em;
34
+ /// padding: 0.5em 5%;
35
+ /// }
36
+ ///
37
+ /// @access public
38
+ /// @since 0.1.0
39
+
40
+ @mixin output-sides( $property, $values, $important: false )
41
+ {
42
+ // output separate property if setting offset or if one side
43
+ // should be omitted
44
+ @if $property == 'offset' or sl-contain($values, null) {
45
+ @each $side in const('CSS_SIDES') {
46
+ // append the side to the property name, or use the side only for offsets
47
+ $prop: if($property == 'offset', $side, '#{$property}-#{$side}');
48
+ // select the side's value from the list of values
49
+ $val: side-value($values, $side);
50
+
51
+ @include css-rule($prop, $val, $important);
52
+ }
53
+ }
54
+
55
+ // output shorthand otherwise
56
+ @else {
57
+ @include css-rule($property, reduce-sides($values), $important);
58
+ }
59
+ }
60
+
61
+ // =sides( $property, $values[, $important ])
62
+ // -----------------------------------------------------------------------------
63
+ /// @alias output-sides
64
+ ///
65
+ /// @access public
66
+ /// @since 0.1.0
67
+
68
+ @mixin sides( $property, $values, $important: false )
69
+ {
70
+ @include output-sides($property, $values, $important);
71
+ }
@@ -0,0 +1,74 @@
1
+ // =============================================================================
2
+ // =ALEKSI - REDUCE-SIDES-LIST
3
+ // =============================================================================
4
+
5
+ @import "SassyLists";
6
+ @import "aleksi/general/throw";
7
+ @import "aleksi/lists/get-nth";
8
+
9
+ // =reduce-sides-list( $list )
10
+ // -----------------------------------------------------------------------------
11
+ /// Reduces a sides-list to its most compact form.
12
+ ///
13
+ /// @param {list} $list - The sides-list to reduce.
14
+ ///
15
+ /// @return {list} - The reduced version of $list.
16
+ /// @throw Error if $list has more then 4 items.
17
+ ///
18
+ /// @access public
19
+ /// @since 0.1.0
20
+ ///
21
+ /// @todo Unit test the 'reduce-sides-list' function
22
+
23
+ @function reduce-sides-list( $list )
24
+ {
25
+ $l: length($list);
26
+
27
+ @if $l > 4 {
28
+ @return throw-error("reduce-sides-list():: $list #{inspect($list)} is not a valid sides-list. Sides-lists can only have 1 to 4 items.");
29
+ }
30
+
31
+ // OPTIMIZATION: single-items can't be reduces
32
+ @if $l == 1 {
33
+ @return $list;
34
+ }
35
+
36
+ // CAUTION: don't remove 3rd unless 4th can be removed as well,
37
+ // and don't remove 3rd unless 2nd can be removed as well otherwise
38
+ // values would be attributed to wrong sides.
39
+ $first: nth($list, 1);
40
+ $second: get-nth($list, 2);
41
+ $third: get-nth($list, 3);
42
+ $fourth: get-nth($list, 4);
43
+
44
+ @if $l == 4 {
45
+ @if $fourth == $second {
46
+ @return reduce-sides-list(sl-without($list, 4));
47
+ }
48
+ }
49
+
50
+ @else if $l == 3 {
51
+ @if $third == $first {
52
+ @return reduce-sides-list(sl-without($list, 3));
53
+ }
54
+ }
55
+
56
+ @else if $l == 2 {
57
+ @return if($second == $first, $first, $list);
58
+ }
59
+
60
+ // no items to remove
61
+ @return $list;
62
+ }
63
+
64
+ // =reduce-sides( $list )
65
+ // -----------------------------------------------------------------------------
66
+ /// @alias reduce-sides-list
67
+ ///
68
+ /// @access public
69
+ /// @since 0.1.0
70
+
71
+ @function reduce-sides( $list )
72
+ {
73
+ @return reduce-sides-list( $list );
74
+ }
@@ -0,0 +1,48 @@
1
+ // =============================================================================
2
+ // =ALEKSI - SIDE-NAME
3
+ // =============================================================================
4
+
5
+ @import "aleksi/config";
6
+ @import "aleksi/config/constants";
7
+ @import "aleksi/general/throw";
8
+
9
+ // =side-name( $index )
10
+ // -----------------------------------------------------------------------------
11
+ /// Retreives the name of side corresponding to a given index in the ordered
12
+ /// list of CSS sides.
13
+ ///
14
+ /// @param {number} $index - The index of the side to retreive.
15
+ ///
16
+ /// @return {string} - The name of the CSS side corresponding to $index.
17
+ /// @throw Error if $index is not an integer
18
+ /// @throw Error if $index is out of scope.
19
+ ///
20
+ /// @access public
21
+ /// @since 0.1.0
22
+ ///
23
+ /// @todo Unit test the 'side-name' function
24
+
25
+ @function side-name( $index )
26
+ {
27
+ @if not is-int($index) {
28
+ @return throw-error('side-for-index():: $index must be an integer. Was #{inspect($index)}.');
29
+ }
30
+
31
+ @if $i > 4 {
32
+ @return throw-error('side-for-index():: $index #{inspect($index)} out of scope. Should be between 1 and 4.');
33
+ }
34
+
35
+ @return nth(const('CSS_SIDES'), $index);
36
+ }
37
+
38
+ // =nth-side( $index )
39
+ // -----------------------------------------------------------------------------
40
+ /// @alias side-name
41
+ ///
42
+ /// @access public
43
+ /// @since 0.1.0
44
+
45
+ @function nth-side( $index )
46
+ {
47
+ @return side-name($index);
48
+ }
@@ -0,0 +1,83 @@
1
+ // =============================================================================
2
+ // =ALEKSI - SIDES-LIST
3
+ // =============================================================================
4
+
5
+ @import "SassyLists";
6
+ @import "aleksi/config";
7
+ @import "aleksi/config/constants";
8
+ @import "aleksi/general/throw";
9
+ @import "aleksi/maps/is-map";
10
+
11
+ // =get-side-value( $list, $side )
12
+ // -----------------------------------------------------------------------------
13
+ /// Retreives the value for the given side in a side-list.
14
+ /// **Note**: Caution, if passed a map, it will be considered a single value
15
+ /// inside a single item sides-list.
16
+ ///
17
+ /// @param {list} $list - The side-list from which to fetch the value
18
+ /// @param {string} $side - The name of the side to retreive in $list
19
+ ///
20
+ /// @return {any} - The value corresponding to the asked in $list
21
+ /// @throw Error if $side is not a valid side name.
22
+ ///
23
+ /// @example scss
24
+ /// $foo: get-side-value(10px 2em, 'left');
25
+ /// // => 2em
26
+ /// $bar: get-side-value(10px 2em, 'top');
27
+ /// // => 10px
28
+ /// $baz: get-side-value(10px 2em 20%, 'bottom');
29
+ /// // => 20%
30
+ /// $wiz: get-side-value(10px, 'right');
31
+ /// // => 10px
32
+ ///
33
+ /// @access public
34
+ /// @since 0.1.0
35
+ ///
36
+ /// @todo Unit test the 'get-side-value' function.
37
+
38
+ @function get-side-value( $list, $side )
39
+ {
40
+ @if type-of($side) != string or (not sl-contain(const('CSS_SIDES'), $side)) {
41
+ @return throw-error("side-list-value():: $side must be either 'top', 'right', 'bottom' or 'left'. Was #{inspect($side)}.");
42
+ }
43
+
44
+ // consider maps as single values inside a single item sides-list
45
+ @if is-map($list) {
46
+ @return $list;
47
+ }
48
+
49
+ $l: length($list);
50
+ $first: nth($list, 1);
51
+
52
+ @if $side == 'top' {
53
+ @return $first;
54
+ }
55
+
56
+ @else if $side == 'right' {
57
+ @return if($l >= 2, nth($list, 2), $first);
58
+ }
59
+
60
+ @else if $side == 'bottom' {
61
+ @return if($l >= 3, nth($list, 3), $first);
62
+ }
63
+
64
+ @else if $side == 'left' {
65
+ @return if($l >= 4, nth($list, 4), if($l >= 2, nth($list, 2), $first));
66
+ }
67
+
68
+ @else {
69
+ @return throw-error('side-list-value():: $side is must be either');
70
+ }
71
+ }
72
+
73
+ // =side-value( $list, $side )
74
+ // -----------------------------------------------------------------------------
75
+ /// @alias get-side-value
76
+ ///
77
+ /// @access public
78
+ /// @since 0.1.0
79
+
80
+ @function side-value( $list, $side )
81
+ {
82
+ @return get-side-value($list, $side);
83
+ }
@@ -0,0 +1,64 @@
1
+ // =============================================================================
2
+ // =ALEKSI - SIDES-FOR-KEYWORD
3
+ // =============================================================================
4
+
5
+ // =sides-shorthand( $side, $value )
6
+ // -----------------------------------------------------------------------------
7
+ /// Converts a value into a shorthan sides-list based on a given keyword.
8
+ /// Recognized keywords are 'all', 'ends', 'sides', 'top', 'right', 'bottom' and
9
+ /// 'left'.
10
+ ///
11
+ /// @param {string} $side - Keyword to use to create the shorthand sides-list
12
+ /// @param {any} $value - The value to set in the resulting shortand sides-list
13
+ ///
14
+ /// @return {list} - Shorthand sides-list containing $value.
15
+ /// @throw Warning if $side is not a recognized sides-list keyword.
16
+ ///
17
+ /// @example scss
18
+ /// $foo: sides-for-keyword('left', 10px);
19
+ /// // => null null null 10px
20
+ /// $bar: sides-for-keyword('all', 10px);
21
+ /// // => 10px
22
+ /// $baz: sides-for-keyword('ends', 10px);
23
+ /// // => 10px null
24
+ /// $wiz: sides-for-keyword('sides', 10px);
25
+ /// // => null 10px
26
+ ///
27
+ /// @access public
28
+ /// @since 0.1.0
29
+ ///
30
+ /// @todo Unit test the 'sides-shorthand' function
31
+
32
+ @function sides-shorthand( $side, $value )
33
+ {
34
+ @if $side == 'all' {
35
+ @return $value;
36
+ }
37
+
38
+ @else if $side == 'ends' {
39
+ @return $value null;
40
+ }
41
+
42
+ @else if $side == 'sides' {
43
+ @return null $value;
44
+ }
45
+
46
+ @else if $side == 'top' {
47
+ @return $value null null;
48
+ }
49
+
50
+ @else if $side == 'right' {
51
+ @return null $value null null;
52
+ }
53
+
54
+ @else if $side == 'bottom' {
55
+ @return null null $value;
56
+ }
57
+
58
+ @else if $side == 'left' {
59
+ @return null null null $value;
60
+ }
61
+
62
+ @return throw-error("sides-for-keyword():: keyword #{inspect($side)} is"
63
+ + " not a recognized keyword for sides-lists. Returning `null`.");
64
+ }
@@ -0,0 +1,63 @@
1
+ // =============================================================================
2
+ // =ALEKSI - TO-SIDES-LIST
3
+ // =============================================================================
4
+
5
+ @import "SassyLists";
6
+ @import "aleksi/config";
7
+ @import "aleksi/config/constants";
8
+ @import "aleksi/general/is-of-type";
9
+ @import "aleksi/general/throw";
10
+ @import "aleksi/lists/contained-in";
11
+ @import "aleksi/sides/reduce-sides";
12
+
13
+ // =sides-map-to-list( $map[, $reduce ])
14
+ // -----------------------------------------------------------------------------
15
+ /// Converts a map of side, value pairs into a sides-list, and optionally
16
+ /// reduces the result.
17
+ ///
18
+ /// @param {map} $map - The map to convert into a sides-list
19
+ /// @param {bool} $reduce [false] - Whether to reduce the resulting sides-list
20
+ ///
21
+ /// @return {list} - The sides-list with values found in $map, in correct order.
22
+ /// @throw Error if $map is not a map.
23
+ /// @throw Warning if $map does not define a key, value pair for every CSS side.
24
+ ///
25
+ /// @example scss
26
+ /// $bar: sides-map-to-list('left': 2em, 'right': 2em, 'top': 10px, 'bottom': 5%);
27
+ /// // => 10px 2em 5% 2em
28
+ ///
29
+ /// @access public
30
+ /// @since 0.1.0
31
+ ///
32
+ /// @todo Unit test the 'sides-map-to-list' function.
33
+
34
+ @function sides-map-to-list( $map, $reduce: false )
35
+ {
36
+ $list: ();
37
+
38
+ @if not is-of-type($map, 'map') {
39
+ @return throw-error('sides-map-to-sides-list():: $map must be a map. Was #{inspect($map)}.');
40
+ }
41
+
42
+ @if not sl-some(map-keys($map), 'contained-in', const('CSS_SIDES')) {
43
+ @return throw-warnig('sides-map-to-sides-list():: $map does not contain any CSS side, value pair.');
44
+ }
45
+
46
+ @each $side in const('CSS_SIDES') {
47
+ $list: append($list, map-get($map, $side));
48
+ }
49
+
50
+ @return if($reduce, reduce-sides-list($list), $list);
51
+ }
52
+
53
+ // =to-sides-list( $map )
54
+ // -----------------------------------------------------------------------------
55
+ /// @alias sides-map-to-list
56
+ ///
57
+ /// @access public
58
+ /// @since 0.1.0
59
+
60
+ @function to-sides-list( $map )
61
+ {
62
+ @return sides-map-to-list($map);
63
+ }
@@ -0,0 +1,57 @@
1
+ // =============================================================================
2
+ // =ALEKSI - TO-SIDES-MAP
3
+ // =============================================================================
4
+
5
+ @import "sassy-maps";
6
+ @import "aleksi/config";
7
+ @import "aleksi/config/constants";
8
+ @import "aleksi/general/throw";
9
+
10
+ // =sides-list-to-map( $list )
11
+ // -----------------------------------------------------------------------------
12
+ /// Converts a given side-list to a map pairing each side with its corresponding
13
+ /// value. If the list has more then 4 items, it will ignore additional items.
14
+ /// **Note**: sides-maps can not be reduced, otherwise a `null` value could
15
+ /// falsely get attributed to a side by using `map-get()`.
16
+ ///
17
+ /// @param {list} $name - The side-list to convert.
18
+ ///
19
+ /// @return {map} - A map pairing each CSS side with the value found in $list.
20
+ /// @throw Warning If $list has more then 4 items.
21
+ ///
22
+ /// @example scss
23
+ /// $foo: sides-list-to-map(10px 2em 5%);
24
+ /// // => ('top': 10px, 'right': 2em, 'bottom': 5%, 'left': 2em)
25
+ ///
26
+ /// @access public
27
+ /// @since 0.1.0
28
+ ///
29
+ /// @todo Unit test the 'sides-list-to-map' function.
30
+
31
+ @function sides-list-to-map( $list )
32
+ {
33
+ $l: length($list);
34
+ $map: ();
35
+
36
+ @if $l >= 4 {
37
+ $w: throw-warning('sides-list-to-map():: $list has more then 4 items. Items 5 and up are being ignored.');
38
+ }
39
+
40
+ @each $side in const('CSS_SIDES') {
41
+ $map: map-set($map, $side, side-value($list, $side));
42
+ }
43
+
44
+ @return $map;
45
+ }
46
+
47
+ // =to-sides-map( $list )
48
+ // -----------------------------------------------------------------------------
49
+ /// @alias sides-list-to-map
50
+ ///
51
+ /// @access public
52
+ /// @since 0.1.0
53
+
54
+ @function to-sides-map( $list )
55
+ {
56
+ @return sides-list-to-map( $list );
57
+ }