sass-list-maps 0.9.1 → 0.9.2

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 +43 -31
  3. data/sass-list-maps.scss +15 -8
  4. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a0f54a6344aa38d278a82007ba51a649e0e4240
4
- data.tar.gz: 1e69cbbe0bbeb61619eab4f4e9ab76357aa4df86
3
+ metadata.gz: fdc88d29473b92024c87d8ed0a9632d54da27d73
4
+ data.tar.gz: c73f8bd8f1d21d41ccdf37d2d4b252bd8bfc17eb
5
5
  SHA512:
6
- metadata.gz: 0be83f8ea160263dcc36de8d13d1dffe5e78c739c5d44ec40df1d297bddaeea380eb195ad6a193524be3fd980c487f103ec59878064e89f63dd1c14d7c3f13cb
7
- data.tar.gz: 2e6fba912d4781c1d78469e20455d3db60c2ae597365584b297ab780919881c8ee3c4cf94152f6e5b96baba9f8694e9f4dec6496b9572ab76c6cf3624ced070e
6
+ metadata.gz: f9ae2bca742ff29fbee7744b30fa7afe64ceb311dfad0a33694dce51e174b5efffd356403305b1c5d67a627492d23a82aa402ddbeef4ec14ca1b8bbdefd277c0
7
+ data.tar.gz: 5bdf3f67eab7ffcdbdab4edda0ca876ca4484db9106f6d4898f1d7e448d9efcf11a341b5e959c21b2bbafa16f1d3400aa9e1c061926ad4a527fb60c7689cf451
data/README.md CHANGED
@@ -1,26 +1,42 @@
1
1
  ## Sass List–Maps
2
2
 
3
- Forward-compatible list-based map (hash) functionality for [libsass](https://github.com/hcatlin/libsass) and [ruby-sass](http://sass-lang.com/) < 3.3.x.
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.
4
4
 
5
5
  ![](sass-hash.jpg)
6
6
 
7
- *Some Sass hash.*
7
+ *Some Sass hash. Not everyone likes this joke somehow.*
8
8
 
9
- ##### Update: You can now install this code as a Bower package:
9
+ ###### Latest Updates
10
+
11
+ * 0.9.2 -- improved performance with `set-nth()` function
12
+ * 0.9.2 -- included `get()`, `merge()`, and `set()` aliases by default
13
+ * now listed at the [sache.in](http://www.sache.in/) directory of Sass & Compass Extensions
14
+
15
+ ###### Try it out
16
+
17
+ You can test-drive these functions [at Sassmeister in this pre-loaded gist](http://sassmeister.com/gist/8645654), and you can use them in your own Sassmeister gists by setting the compiler to Sass 3.2.x or libsass and including the "Sass List–Maps" extension in the control panel.
18
+
19
+ ###### Install it
20
+
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:
10
22
 
11
23
  ```sh
24
+ # installation with bower
12
25
  bower install sass-list-maps
26
+
27
+ # installation with rubygems, for compass
28
+ gem install sass-list-maps
13
29
  ```
14
30
 
15
31
  ### Introduction
16
32
 
17
- Maps (also known as hashes or objects\*) allow dynamic creating, setting and retrieving of data. They are supported natively in ruby-sass as of version 3.3.rc1 with new syntax and functions; but for earlier ruby-sass versions—and for the increasingly popular ultra-fast libsass C-based compiler (until the point at which maps are integrated there natively)—this is an alternative solution. These functions feature-match ruby-sass 3.3's map functionality and syntax as closely as possible, using the `list` data-type. Additionally, some functions are provided to extend this map functionality with nested getting and merging/setting.
33
+ Maps (also known as hashes or objects\*) allow dynamic creating, setting and retrieving of data. They are supported natively in ruby-sass as of version 3.3.x with dedicated syntax and functions; but for earlier ruby-sass versions—and for the increasingly popular libsass C-based compiler (until the point at which maps are integrated there natively)—this is an alternative solution. These functions feature-match ruby-sass 3.3's map functionality as closely as possible using the `list` data-type. Additional functions are also provided to extend this functionality with nested getting and merging/setting.
18
34
 
19
- \* objects (as in javascript) are not exactly the same thing as maps and hashes, but for these purposes close enough.
35
+ *\* objects (as in javascript) are not exactly the same thing as maps and hashes, but for these purposes close enough.*
20
36
 
21
37
  ### 'List-map' syntax
22
38
 
23
- List-maps—as I'll refer to them for the sake of clarity, as opposed to native maps—are like any other list in Sass but must be formatted to work with these functions. The syntax I recommend keeps as close as possible to that of native maps, but differs in that there are of course no colons (`:`), and the placement of commas is more critical (trailing commas—i.e. commas after the last item—are allowed in native maps and in lists in ruby-sass 3.3+ but not in any other version):
39
+ List-maps—as I'll refer to them for the sake of clarity, as opposed to native maps—are like any other list in Sass but must be formatted carefully, as a list of pairs. The formatting I recommend keeps as close as possible to the syntax of native maps, with the difference that there no colons (`:`), and the placement of commas is more critical (e.g. trailing commas—commas after the last item—are allowed in native maps and in lists in ruby-sass 3.3+ but not in any other version):
24
40
 
25
41
 
26
42
  ```scss
@@ -36,7 +52,7 @@ in any version/compiler other than ruby-sass 3.3+
36
52
  $native-map: ( alpha: 1, beta: 2, gamma: 3,);
37
53
  ```
38
54
 
39
- A list-map is a list of pairs: it can be of any length, but each item in that list must be a list of two. The first item in each pair is the 'key', the second the 'value'. This 'value' can be a primitive (number, boolean, string) or a list (can also be another list-map). A 'nested' list-map (list-map within a list-map) therefore, looks like this in its simplest form (compared again to a native map):
55
+ Being a list of pairs then, a list-map list can be of any length, but each item in that list must be a list of exactly two. The first of these is the 'key' and is usually a string; the second is the 'value' and can be of any type, including being another list (of pairs!). In this way list-maps can be nested. Such a 'nested' list-map looks like this in its simplest form (compared again to a native map):
40
56
 
41
57
  ```scss
42
58
  $list-map-z: (
@@ -56,15 +72,15 @@ $native-map-z: (
56
72
  );
57
73
  ```
58
74
 
59
- It should be clear that list-maps and native maps are very similar. In fact they are in principle the same. For this reason it was possible to 'reverse engineer' ruby-sass' 3.3+ map logic to work with lists.
75
+ It should be clear that list-maps and native maps are very similar; in fact they are in principle the same. For this reason it was possible to 'reverse engineer' the map functions of ruby-sass' 3.3+ to use simple lists.
60
76
 
61
77
  ### 'List-map' functions
62
78
 
63
- The functions for 'list-maps' have the same names as the native map functions in ruby-sass 3.3+. Therefore, the following code assume a sass environment other than ruby running sass 3.3.rc1 or higher, where they would otherwise conflict.
79
+ The functions for 'list-maps' have the same names as the map functions in ruby-sass >= 3.3.x, which means that if they were used in ruby-sass 3.3.x or higher they would conflict.Therefore, the following code assume a sass environment other than that (either ruby-sass <3.3 or libsass.
64
80
 
65
81
  #### Basic
66
82
 
67
- All current ruby-sass map functions—as of this writing—are implemented, including `map-get($list, $key)`, `map-merge($list1, $list2)`, `map-remove($list, $key)`, `map-keys($list)`, `map-values($list)`, and `map-has-key($list, $key)`. As with native maps, standard list functions can also be used on list-maps since they are just lists anyway.
83
+ All of the current—as of this writing—map functions are implemented. These include `map-get($list, $key)`, `map-merge($list1, $list2)`, `map-remove($list, $key)`, `map-keys($list)`, `map-values($list)`, and `map-has-key($list, $key)`. As with native maps, standard list functions can also be used on list-maps since they are lists anyway.
68
84
 
69
85
  ##### 1. `map-keys($list)`, `map-values($list)`, `map-has-key($list, $key)`
70
86
 
@@ -109,18 +125,16 @@ $short-map: map-remove($list-map, alpha);
109
125
  // -> $short-map = ( beta 2, gamma 3)
110
126
  ```
111
127
 
112
- **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 specify 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()` helper function (included) if you want to create a map-list with only one pair.
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.
113
129
 
114
130
  #### Advanced
115
131
 
116
- In addition to list-map versions of ruby-sass 3.3+ core map functions, this repo includes 'depth' versions of `map-get()` and `map-merge()`, suffixed with `-z`.
117
-
118
- The `map-get-z()` function will retrieve values from a list-map according to a chain of keys (similar to the way nested array/hash/object values are accessed in other languages);
119
-
120
- ...while the `map-merge-z()` function takes a chain of keys to indicate where (at what depth) to merge, but interprets its final argument as the value to be merged. This value can be of any type including being 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.
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`.
121
133
 
122
134
  ##### 4. `map-get-z($list, $keys...)`
123
135
 
136
+ The `map-get-z()` function will retrieve values from a list-map according to a chain of keys (similar to the way nested array/hash/object values are accessed in other languages):
137
+
124
138
  ```scss
125
139
  @import "sass-list-maps";
126
140
 
@@ -141,6 +155,8 @@ $list-map-z: (
141
155
 
142
156
  ##### 5. `map-merge-z($list, $keys-and-value...)`
143
157
 
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
+
144
160
  ```scss
145
161
  @import "sass-list-maps";
146
162
 
@@ -164,20 +180,16 @@ $new-map4-z: map-merge-z($list-map-z, delta, epsilon, 5);
164
180
  // -> ( alpha ( beta ( gamma 3 ) ), ( delta ( epsilon 5 ) ) )
165
181
  ```
166
182
 
167
- #### Customization
183
+ ##### 6. Unified syntax
168
184
 
169
- Note that in the above examples, the `-z` suffixed functions are effectively identical to their 'simple' counterparts if given only two arguments. This means they can actually replace them. Moreover, `map-merge-z($list, $keys-and-value...)` and `map-merge-z($list1, $list2)` argument patterns are also interchangeable. This means that `map-merge-z()` can also be treated as if it were `map-set-z($list, $keys..., $value)` if you prefer the semantics of that naming. My own preference is to write the following and call it a day:
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:
170
186
 
171
187
  ```scss
172
- @function get($args...) {
173
- @return map-get-z($args...);
174
- }
175
- @function merge($args...) {
176
- @return map-merge-z($args...);
177
- }
178
- @function set($args...) {
179
- @return map-merge-z($args...);
180
- }
188
+ @function get($args...) { @return map-get-z($args...); }
189
+
190
+ @function merge($args...) { @return map-merge-z($args...); }
191
+
192
+ @function set($args...) { @return map-merge-z($args...); }
181
193
  ```
182
194
 
183
195
  ### Caveats
@@ -192,12 +204,12 @@ There are a few points that bear mentioning/repeating:
192
204
  ### To-Dos
193
205
 
194
206
  * Make a depth-based version of `map-remove()`
195
- * ~~Make this in to a bower package~~ *done*
196
- * Make this in to a gem
207
+ * <del>Make this in to a bower package</del> *done*
208
+ * <del>Make this in to a gem</del> *done*
197
209
  * Push a native maps version of the 'advanced' functions above
198
210
 
199
211
  ### Acknowledgements
200
212
 
201
- First and foremost, my 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 painless (relatively).
213
+ 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.
202
214
 
203
- Also acknowledgements to @HugoGiraudel for [SassyLists](http://sassylists.com/), from which I borrowed the `slice()` and `replace-nth()` list functions, and his `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 and libsass.
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.
data/sass-list-maps.scss CHANGED
@@ -1,4 +1,4 @@
1
- // list helper functions (some from SassyLists)
1
+ // list helper functions
2
2
 
3
3
  @function list($args...) {
4
4
  $output: ();
@@ -14,11 +14,12 @@
14
14
  $output: append($output, nth($list, $i), $sep); }
15
15
  @return $output;
16
16
  }
17
- @function replace-nth($list, $value, $index, $sep: 'comma') {
18
- $output: ();
19
- @for $i from 1 through length($list) {
20
- @if $i == $index { $output: append($output, $value, $sep); }
21
- @else { $output: append($output, nth($list, $i), $sep); } }
17
+ @function set-nth($list, $index, $value, $sep: 'comma') {
18
+ $length: length($list); $output: ();
19
+ @if $index > $length or $index <= 0 { @return $list; }
20
+ @for $i from 1 through $index - 1 { $output: append($output, nth($list, $i), $sep); }
21
+ $output: append($output, $value, $sep);
22
+ @for $i from $index + 1 through $length { $output: append($output, nth($list, $i), $sep); }
22
23
  @return $output;
23
24
  }
24
25
 
@@ -56,7 +57,7 @@
56
57
  $keys1: map-keys($list1);
57
58
  @each $tuple in $list2 {
58
59
  $index: index($keys1, tuple-key($tuple));
59
- @if $index { $list1: replace-nth($list1, $tuple, $index); }
60
+ @if $index { $list1: set-nth($list1, $index, $tuple); }
60
61
  @else { $list1: append($list1, $tuple, 'comma'); } }
61
62
  @return $list1;
62
63
  }
@@ -87,4 +88,10 @@
87
88
  @if $i == $key-length { $old-list: $list; } @else { $old-list: map-get-z($list, slice($keys-and-value, 1, $key-length - $i)...) or (); }
88
89
  $value: map-merge($old-list, $new-list); } }
89
90
  @return $value;
90
- }
91
+ }
92
+
93
+ // aliases: keep it simple stupid
94
+
95
+ @function get($args...) { @return map-get-z($args...); }
96
+ @function merge($args...) { @return map-merge-z($args...); }
97
+ @function set($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.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lu Nelson
@@ -38,8 +38,7 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.2.0
41
- description: Forward-compatible maps-functionality for all versions/compilers of sass
42
- which do not have a native map data-type
41
+ description: Forward-compatible map functionality for libsass and ruby-sass <3.3
43
42
  email: lunelson@gmail.com
44
43
  executables: []
45
44
  extensions: []
@@ -72,5 +71,5 @@ rubyforge_project:
72
71
  rubygems_version: 2.2.1
73
72
  signing_key:
74
73
  specification_version: 4
75
- summary: maps-as-lists for libsass and ruby-sass <3.3
74
+ summary: Maps for libsass and ruby-sass <3.3
76
75
  test_files: []