sass-list-maps 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -17
  3. data/sass-list-maps.scss +10 -8
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdc88d29473b92024c87d8ed0a9632d54da27d73
4
- data.tar.gz: c73f8bd8f1d21d41ccdf37d2d4b252bd8bfc17eb
3
+ metadata.gz: a0f364c482873fa534b9168cfeeb88ec97a21dab
4
+ data.tar.gz: 9191db0a554e5fbeb72884143607c3f3cc629850
5
5
  SHA512:
6
- metadata.gz: f9ae2bca742ff29fbee7744b30fa7afe64ceb311dfad0a33694dce51e174b5efffd356403305b1c5d67a627492d23a82aa402ddbeef4ec14ca1b8bbdefd277c0
7
- data.tar.gz: 5bdf3f67eab7ffcdbdab4edda0ca876ca4484db9106f6d4898f1d7e448d9efcf11a341b5e959c21b2bbafa16f1d3400aa9e1c061926ad4a527fb60c7689cf451
6
+ metadata.gz: 0cca799423392ec54da72fab4411c592896612b515a89c0aaa1775d985c88bc4977de61681e5ac892fbd432390c4bcd02dbcdc72fba63901b3348c1a4f915f7a
7
+ data.tar.gz: c03d6c7c3e0f1c25b5e1eecfc649adb981169f706a83f0c30f13f0505fe542fac454fc3f81fa65b7862fb9f43923d4a0d3b70a6b34c68353352b32f33009baaa
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
  ## Sass List–Maps
2
2
 
3
- Forward-compatible map (hash) functionality for [libsass](https://github.com/hcatlin/libsass) and [ruby-sass](http://sass-lang.com/) < 3.3.x using lists.
3
+ Forward-compatible map (hash) functionality for [libsass](https://github.com/hcatlin/libsass) and [ruby-sass](http://sass-lang.com/) 3.2.x using lists.
4
4
 
5
5
  ![](sass-hash.jpg)
6
6
 
7
- *Some Sass hash. Not everyone likes this joke somehow.*
7
+ *Some Sass hash. Not everyone likes this joke.*
8
8
 
9
9
  ###### Latest Updates
10
10
 
11
- * 0.9.2 -- improved performance with `set-nth()` function
11
+ * 0.9.3 -- deprecated `list()` function in favor of native `zip()` for creating single-pair list-maps
12
+ * 0.9.2 -- improved merge performance with rewritten `set-nth()` function
12
13
  * 0.9.2 -- included `get()`, `merge()`, and `set()` aliases by default
13
14
  * now listed at the [sache.in](http://www.sache.in/) directory of Sass & Compass Extensions
14
15
 
@@ -18,7 +19,7 @@ You can test-drive these functions [at Sassmeister in this pre-loaded gist](http
18
19
 
19
20
  ###### Install it
20
21
 
21
- Sass List-Maps can now be installed as a Bower component or a gem (Compass extension) as alternative to cloning, downloading or cutting and pasting from this repo:
22
+ Sass List-Maps can be installed as a Bower component or a gem (Compass extension) as alternative to cloning, downloading or cutting and pasting from this repo:
22
23
 
23
24
  ```sh
24
25
  # installation with bower
@@ -118,18 +119,18 @@ $list-map: ( alpha 1, beta 2, gamma 3 );
118
119
 
119
120
  $list-map: ( alpha 1, beta 2, gamma 3 );
120
121
 
121
- $new-map: map-merge($list-map, list(gamma 4));
122
+ $new-map: map-merge($list-map, zip(gamma, 4));
122
123
  // -> $new-map = ( alpha 1, beta 2, gamma 4 )
123
124
 
124
125
  $short-map: map-remove($list-map, alpha);
125
126
  // -> $short-map = ( beta 2, gamma 3)
126
127
  ```
127
128
 
128
- **NB**: notice the use of the `list()` function in the second example. This is due to the fact that Sass has no succinct way to create a list containing another list, if the containing list is only 1 element in length. Since a list-map must always be a list-of-lists—even if it only contains one item—you must use the `list()` function (included here) when creating list-maps of only one key-value pair.
129
+ **NB**: notice the use of the `zip()` function in the second example. This is used because Sass has no way to create a list containing a single item that is also a list, using notation alone. For list-maps with only one pair therefore, we use the `zip()` function to combine its arguments in to a list of pairs.
129
130
 
130
131
  #### Advanced
131
132
 
132
- In addition to the core ruby-sass 3.3+ map functions, this repo includes 'depth' versions of `map-get()` and `map-merge()`, suffixed here with `-z`.
133
+ In addition to the core ruby-sass 3.3+ map functions, this library includes 'depth' or 'nested' versions of `map-get()` and `map-merge()` -- suffixed here with `-z`.
133
134
 
134
135
  ##### 4. `map-get-z($list, $keys...)`
135
136
 
@@ -155,7 +156,7 @@ $list-map-z: (
155
156
 
156
157
  ##### 5. `map-merge-z($list, $keys-and-value...)`
157
158
 
158
- The `map-merge-z()` function takes a chain of keys to indicate where (at what depth) to merge, interpreting its final argument as the value to be merged. This value can be of any type including another list/list-map. Note that if only one key/value argument is passed and it is not a list, it is interpreted as the key, and an empty list is merged in as the value:
159
+ The `map-merge-z()` function takes a chain of keys to indicate where (at what depth) to merge, and takes its final argument as the value to be merged. This value can be of any type including another list/list-map. Note that if only one key/value argument is passed and it is not a list, it is interpreted as the key, and an empty list is merged in as the value:
159
160
 
160
161
  ```scss
161
162
  @import "sass-list-maps";
@@ -180,15 +181,23 @@ $new-map4-z: map-merge-z($list-map-z, delta, epsilon, 5);
180
181
  // -> ( alpha ( beta ( gamma 3 ) ), ( delta ( epsilon 5 ) ) )
181
182
  ```
182
183
 
183
- ##### 6. Unified syntax
184
+ ##### 6. UNIFIED SYNTAX: `get()`, `merge()`, `set()`
184
185
 
185
- Note that in the above examples, the `-z` suffixed functions work like their 'simple' counterparts if given only two arguments. This is by design, so that they can transparently replace them. Moreover, the `map-merge-z($list, $keys-and-value...)` and `map-merge-z($list1, $list2)` argument patterns are interchangeable. This means that `map-merge-z()` can be treated as if it were `map-set-z($list, $keys..., $value)`, which is a common alternative syntax when dealing with hashes. In light of this, the following aliased functions are provided—as of version 0.9.2—to unify and simplify the usage of map functions as much as is possible:
186
+ Note that in the above 'advanced' examples, the `-z` suffixed functions work like their 'simple' counterparts if given only two arguments, which means they can transparently replace them and will respond to the number of 'key' arguments required. Moreover, `map-merge-z($list, $key[s...], $value)` and `map-merge-z($list1, $list2)` argument patterns are interchangeable, which means that `map-merge-z()` can be treated as if it were `map-set-z()`, which can be a more intuitive semantic. The following aliases are provided—as of version 0.9.2—to unify and simplify all of the above list-map logic to three universal functions:
186
187
 
187
188
  ```scss
189
+ @import "sass-list-maps";
190
+
191
+ // get($list, $key[s...])
192
+ // accepts 1 or more key args as target, returns value
188
193
  @function get($args...) { @return map-get-z($args...); }
189
194
 
195
+ // merge($list1, [$keys...,] $list2)
196
+ // accepts 0 or more key args as target, merges list at target
190
197
  @function merge($args...) { @return map-merge-z($args...); }
191
198
 
199
+ // set($list, $key[s...], $value)
200
+ // accepts 1 or more key args as target, sets value at target
192
201
  @function set($args...) { @return map-merge-z($args...); }
193
202
  ```
194
203
 
@@ -196,20 +205,18 @@ Note that in the above examples, the `-z` suffixed functions work like their 'si
196
205
 
197
206
  There are a few points that bear mentioning/repeating:
198
207
 
199
- * operating on global variables in libsass and in ruby-sass versions before 3.3.x works differently than in 3.3+. You can make changes to global variables from inside a mixin scope but you can't create them from there. This has implications for mixins that do operations on global list-maps.
200
- * as noted, the 'list-map' syntax is less forgiving than that of native maps (watch the commas). Also, it lacks any error-checking (e.g. native maps will produce a warning if you have duplicate keys). And obviously fancy features of native maps such as passing a map to a function in the form `my-function($map...)` whereupon you can reference the key/value elements inside the function as if they were named variables, doesn't work with list-maps.
201
- * as noted, the `list()` function is required if you want to make a list-map with only one pair, since Sass has no short way of specifying a list of a list like that (e.g. `$list: ((key value));` doesn't work, you need `$list: list(key value);`).
202
- * as of this writing, this code contains no test-suites or inline error-catches or warnings of any kind. I've been using it in my own work but there are surely edge-cases I haven't seen. I welcome reports and contributions.
208
+ * operating on global variables in libsass and in ruby-sass 3.2.x or earlier, works differently than in 3.3.x+: You can make changes to global variables from inside a mixin scope but you can't create them from there. There is no `!global` flag. This has implications for mixins that operate on global list-maps.
209
+ * as noted, the 'list-map' syntax is less forgiving than that of native maps (watch your commas). Also, it lacks any error-checking (e.g. native maps will produce a warning if you have duplicate keys). And obviously fancy features of native maps such as passing a map to a function in the form `my-function($map...)` whereupon you can reference the key/value elements inside the function as if they were named variables, doesn't work with list-maps.
210
+ * as noted, the `zip()` function is required if you want to make a list-map with only one pair, since Sass has no short way of specifying a list with one list inside (e.g. `$list: ((key value));` doesn't work, you need `$list: zip(key, value);`).
211
+ * as of this writing, this code contains no test-suites or inline error-catches or warnings of any kind. I've been using it in my own work but there are surely edge-cases I haven't seen. I welcome reports and contributions!
203
212
 
204
213
  ### To-Dos
205
214
 
206
215
  * Make a depth-based version of `map-remove()`
207
- * <del>Make this in to a bower package</del> *done*
208
- * <del>Make this in to a gem</del> *done*
209
216
  * Push a native maps version of the 'advanced' functions above
210
217
 
211
218
  ### Acknowledgements
212
219
 
213
220
  First and foremost, gratitude to the core Sass devs (@nex3 and @chriseppstein) for their tireless advancement of the gold-standard of CSS pre-processing, and secondly to @jedfoster and @anotheruiguy for [Sassmeister](http://sassmeister.com/), which makes developing complex functions and mixins relatively painless.
214
221
 
215
- Also acknowledgements to @HugoGiraudel for [SassyLists](http://sassylists.com/), from which I borrowed some functions early on, and especially `debug()`, without which I would not have been able to figure out what was going on (and going wrong) in ruby-sass 3.2 and libsass.
222
+ Also acknowledgements to @HugoGiraudel for [SassyLists](http://sassylists.com/), from which I adapted some early functions, and especially for his list `debug()` function, without which I would not have been able to figure out what was going on (and going wrong) in ruby-sass 3.2.x and libsass.
data/sass-list-maps.scss CHANGED
@@ -1,13 +1,11 @@
1
1
  // list helper functions
2
+ // 0.9.3 -- "list()" now deprecated in favor of "zip()".
2
3
 
3
4
  @function list($args...) {
4
5
  $output: ();
5
6
  @each $arg in $args { $output: append($output, $arg); }
6
7
  @return $output;
7
8
  }
8
- @function unlist($list) {
9
- @return if(length($list) == 1, nth($list, 1), $list);
10
- }
11
9
  @function slice($list, $start: 1, $end: length($list), $sep: 'comma') {
12
10
  $output: ();
13
11
  @for $i from $start through $end {
@@ -23,10 +21,13 @@
23
21
  @return $output;
24
22
  }
25
23
 
26
- // list-map helper functions, purely semantic
24
+ // list-map helper functions
25
+ // 0.9.3 -- key() and value() tentatively added as alternatives to 'tuple-' named funcs
27
26
 
28
27
  @function tuple-key($tuple) { @return nth($tuple, 1); }
29
28
  @function tuple-value($tuple) { @return nth($tuple, 2); }
29
+ @function key($tuple) { @return nth($tuple, 1); }
30
+ @function value($tuple) { @return nth($tuple, 2); }
30
31
 
31
32
  // list-map versions of map-keys(), -values() and -has-key() functions
32
33
 
@@ -68,7 +69,7 @@
68
69
  @return $out;
69
70
  }
70
71
 
71
- // advanced: map-get-z() and map-merge-z()
72
+ // deep/nested map functions: map-get-z() and map-merge-z()
72
73
 
73
74
  @function map-get-z($list, $keys...) {
74
75
  @each $key in $keys {
@@ -80,17 +81,18 @@
80
81
  $arg-length: length($keys-and-value);
81
82
  $value: nth($keys-and-value, $arg-length);
82
83
  $key-length: $arg-length - 1;
83
- @if $key-length == 0 { $value: if(type-of($value) == 'list', map-merge($list, $value), map-merge($list, list($value ()))); }
84
+ @if $key-length == 0 { $value: if(type-of($value) == 'list', map-merge($list, $value), map-merge($list, zip($value, ()))); }
84
85
  @else { $start: if(type-of($value) == 'list', 0, 1);
85
86
  @for $i from $start through $key-length {
86
87
  $new-list: (); $old-list: ();
87
- @if $i == 0 { $new-list: $value; } @else { $new-list: list(nth($keys-and-value, $key-length + 1 - $i) $value); }
88
+ @if $i == 0 { $new-list: $value; } @else { $new-list: zip(nth($keys-and-value, $key-length + 1 - $i), $value); }
88
89
  @if $i == $key-length { $old-list: $list; } @else { $old-list: map-get-z($list, slice($keys-and-value, 1, $key-length - $i)...) or (); }
89
90
  $value: map-merge($old-list, $new-list); } }
90
91
  @return $value;
91
92
  }
92
93
 
93
- // aliases: keep it simple stupid
94
+ // 0.9.2 -- aliases
95
+ // these replace map-*() and map-*-z() variants with a single universal function
94
96
 
95
97
  @function get($args...) { @return map-get-z($args...); }
96
98
  @function merge($args...) { @return map-merge-z($args...); }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass-list-maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lu Nelson
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.2.0
41
- description: Forward-compatible map functionality for libsass and ruby-sass <3.3
41
+ description: Forward-compatible map functionality for libsass and ruby-sass 3.2.x
42
42
  email: lunelson@gmail.com
43
43
  executables: []
44
44
  extensions: []
@@ -71,5 +71,5 @@ rubyforge_project:
71
71
  rubygems_version: 2.2.1
72
72
  signing_key:
73
73
  specification_version: 4
74
- summary: Maps for libsass and ruby-sass <3.3
74
+ summary: Maps for libsass and ruby-sass 3.2.x
75
75
  test_files: []