diff options
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | src/_props.scss | 30 | ||||
-rw-r--r-- | src/props-shortcodes.scss | 26 | ||||
-rw-r--r-- | test/_props.scss | 60 |
4 files changed, 65 insertions, 63 deletions
@@ -236,18 +236,18 @@ Example usage: | |||
236 | // Usage: | 236 | // Usage: |
237 | 237 | ||
238 | p { | 238 | p { |
239 | color: iro-props-get(--text, 'light'); // #222 | 239 | color: iro-props-get-static(--text, 'light'); // #222 |
240 | background-color: iro-props-get(--background, 'light'); // #fff | 240 | background-color: iro-props-get-static(--background, 'light'); // #fff |
241 | } | 241 | } |
242 | 242 | ||
243 | a { | 243 | a { |
244 | color: iro-props-get(--link --idle --text, 'light'); // #000 | 244 | color: iro-props-get-static(--link --idle --text, 'light'); // #000 |
245 | border-bottom: 1px solid iro-props-get(--link --idle --underline, 'light'); // #f00 | 245 | border-bottom: 1px solid iro-props-get-static(--link --idle --underline, 'light'); // #f00 |
246 | text-decoration: none; | 246 | text-decoration: none; |
247 | 247 | ||
248 | &:hover { | 248 | &:hover { |
249 | color: iro-props-get(--link --hover --text, 'light'); // #f00 | 249 | color: iro-props-get-static(--link --hover --text, 'light'); // #f00 |
250 | border-bottom-color: iro-props-get(--link --hover --underline, 'light'); // #f00 | 250 | border-bottom-color: iro-props-get-static(--link --hover --underline, 'light'); // #f00 |
251 | } | 251 | } |
252 | } | 252 | } |
253 | ``` | 253 | ``` |
diff --git a/src/_props.scss b/src/_props.scss index 86a2215..5577f3a 100644 --- a/src/_props.scss +++ b/src/_props.scss | |||
@@ -77,7 +77,7 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
77 | /// | 77 | /// |
78 | /// Get the current namespace name. | 78 | /// Get the current namespace name. |
79 | /// | 79 | /// |
80 | @function iro-props-ns-name() { | 80 | @function iro-props-namespace() { |
81 | $noop: iro-context-assert-stack-must-contain($iro-props-namespace-context-id, 'namespace'); | 81 | $noop: iro-context-assert-stack-must-contain($iro-props-namespace-context-id, 'namespace'); |
82 | 82 | ||
83 | $data: nth(iro-context-get($iro-props-namespace-context-id, 'namespace'), 2); | 83 | $data: nth(iro-context-get($iro-props-namespace-context-id, 'namespace'), 2); |
@@ -172,7 +172,7 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
172 | /// | 172 | /// |
173 | /// @throw If there was no match for $key and $default is null | 173 | /// @throw If there was no match for $key and $default is null |
174 | /// | 174 | /// |
175 | @function iro-props-get($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { | 175 | @function iro-props-get-static($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { |
176 | @if not map-has-key($iro-props-trees, $tree) { | 176 | @if not map-has-key($iro-props-trees, $tree) { |
177 | @error 'Unknown tree "#{$tree}".'; | 177 | @error 'Unknown tree "#{$tree}".'; |
178 | } | 178 | } |
@@ -205,9 +205,9 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
205 | 205 | ||
206 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { | 206 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { |
207 | @if length($result) == 2 { | 207 | @if length($result) == 2 { |
208 | $result: iro-props-get($tree: nth($result, 2), $global: true); | 208 | $result: iro-props-get-static($tree: nth($result, 2), $global: true); |
209 | } @else { | 209 | } @else { |
210 | $result: iro-props-get(nth($result, 3), nth($result, 2), $global: true); | 210 | $result: iro-props-get-static(nth($result, 3), nth($result, 2), $global: true); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | } @else { | 213 | } @else { |
@@ -223,9 +223,9 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
223 | 223 | ||
224 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { | 224 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { |
225 | @if length($result) == 2 { | 225 | @if length($result) == 2 { |
226 | $result: iro-props-get($tree: nth($result, 2), $global: true); | 226 | $result: iro-props-get-static($tree: nth($result, 2), $global: true); |
227 | } @else { | 227 | } @else { |
228 | $result: iro-props-get(nth($result, 3), nth($result, 2), $global: true); | 228 | $result: iro-props-get-static(nth($result, 3), nth($result, 2), $global: true); |
229 | } | 229 | } |
230 | } | 230 | } |
231 | } | 231 | } |
@@ -250,9 +250,9 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
250 | /// | 250 | /// |
251 | /// @return {string} var() | 251 | /// @return {string} var() |
252 | /// | 252 | /// |
253 | @function iro-props-get-native($key, $tree: null, $default: null, $global: false) { | 253 | @function iro-props-get($key, $tree: $iro-props-default-tree, $default: null, $global: false) { |
254 | @if $tree != null { | 254 | @if $tree != null { |
255 | $noop: iro-props-get($key, $tree, $default); | 255 | $noop: iro-props-get-static($key, $tree, $default); |
256 | } | 256 | } |
257 | 257 | ||
258 | @if not $global { | 258 | @if not $global { |
@@ -295,8 +295,8 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
295 | /// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use | 295 | /// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use |
296 | /// @param {string} $root [()] - Sub-tree to use for assignment | 296 | /// @param {string} $root [()] - Sub-tree to use for assignment |
297 | /// | 297 | /// |
298 | @mixin iro-props-assign-native($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { | 298 | @mixin iro-props-assign($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { |
299 | $map: iro-props-get($root, $tree); | 299 | $map: iro-props-get-static($root, $tree); |
300 | $map: map-remove($map, $skip...); | 300 | $map: map-remove($map, $skip...); |
301 | 301 | ||
302 | @if type-of($prefix) == list { | 302 | @if type-of($prefix) == list { |
@@ -311,22 +311,22 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | @include iro-props-assign-native-internal($map, $prefix); | 314 | @include iro-props-assign-internal($map, $prefix); |
315 | } | 315 | } |
316 | 316 | ||
317 | /// | 317 | /// |
318 | /// @access private | 318 | /// @access private |
319 | /// | 319 | /// |
320 | @mixin iro-props-assign-native-internal($map, $prefix: '', $ref-depth: $iro-props-native-assing-max-depth) { | 320 | @mixin iro-props-assign-internal($map, $prefix: '', $ref-depth: $iro-props-native-assing-max-depth) { |
321 | @each $key, $value in $map { | 321 | @each $key, $value in $map { |
322 | $rd: $ref-depth; | 322 | $rd: $ref-depth; |
323 | @if type-of($value) == list and nth($value, 1) == 'iro-prop-ref' { | 323 | @if type-of($value) == list and nth($value, 1) == 'iro-prop-ref' { |
324 | @if $ref-depth != 0 { | 324 | @if $ref-depth != 0 { |
325 | $rd: $rd - 1; | 325 | $rd: $rd - 1; |
326 | @if length($value) == 2 { | 326 | @if length($value) == 2 { |
327 | $value: iro-props-get($tree: nth($value, 2)); | 327 | $value: iro-props-get-static($tree: nth($value, 2)); |
328 | } @else { | 328 | } @else { |
329 | $value: iro-props-get(nth($value, 3), nth($value, 2)); | 329 | $value: iro-props-get-static(nth($value, 3), nth($value, 2)); |
330 | } | 330 | } |
331 | } @else { | 331 | } @else { |
332 | $value: null; | 332 | $value: null; |
@@ -335,7 +335,7 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
335 | @if type-of($value) != map { | 335 | @if type-of($value) != map { |
336 | #{$prefix + $key}: #{$value}; | 336 | #{$prefix + $key}: #{$value}; |
337 | } @else { | 337 | } @else { |
338 | @include iro-props-assign-native-internal($value, $prefix + $key, $rd); | 338 | @include iro-props-assign-internal($value, $prefix + $key, $rd); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | } | 341 | } |
diff --git a/src/props-shortcodes.scss b/src/props-shortcodes.scss index 2c678a7..e3e3d06 100644 --- a/src/props-shortcodes.scss +++ b/src/props-shortcodes.scss | |||
@@ -10,14 +10,16 @@ | |||
10 | /// @alias iro-props-namespace | 10 | /// @alias iro-props-namespace |
11 | /// | 11 | /// |
12 | @mixin namespace($name) { | 12 | @mixin namespace($name) { |
13 | @include iro-props-namespace($name); | 13 | @include iro-props-namespace($name) { |
14 | @content; | ||
15 | } | ||
14 | } | 16 | } |
15 | 17 | ||
16 | /// | 18 | /// |
17 | /// @alias iro-props-ns-name | 19 | /// @alias iro-props-namespace |
18 | /// | 20 | /// |
19 | @function namespace() { | 21 | @function namespace() { |
20 | @return iro-props-ns-name(); | 22 | @return iro-props-namespace(); |
21 | } | 23 | } |
22 | 24 | ||
23 | /// | 25 | /// |
@@ -49,24 +51,24 @@ | |||
49 | } | 51 | } |
50 | 52 | ||
51 | /// | 53 | /// |
52 | /// @alias iro-props-get | 54 | /// @alias iro-props-get-static |
53 | /// | 55 | /// |
54 | @function prop($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { | 56 | @function static($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { |
55 | @return iro-props-get($key, $tree, $default, $global); | 57 | @return iro-props-get-static($key, $tree, $default, $global); |
56 | } | 58 | } |
57 | 59 | ||
58 | /// | 60 | /// |
59 | /// @alias iro-props-get-native | 61 | /// @alias iro-props-get |
60 | /// | 62 | /// |
61 | @function n-prop($key, $tree: null, $default: null, $global: false) { | 63 | @function prop($key, $tree: $iro-props-default-tree, $default: null, $global: false) { |
62 | @return iro-props-get-native($key, $tree, $default, $global); | 64 | @return iro-props-get($key, $tree, $default, $global); |
63 | } | 65 | } |
64 | 66 | ||
65 | /// | 67 | /// |
66 | /// @alias iro-props-assign-native | 68 | /// @alias iro-props-assign |
67 | /// | 69 | /// |
68 | @mixin n-assign($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { | 70 | @mixin assign($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { |
69 | @include iro-props-assign-native($tree, $root, $skip, $prefix, $global); | 71 | @include iro-props-assign($tree, $root, $skip, $prefix, $global); |
70 | } | 72 | } |
71 | 73 | ||
72 | /// | 74 | /// |
diff --git a/test/_props.scss b/test/_props.scss index 982fc2f..021ed4c 100644 --- a/test/_props.scss +++ b/test/_props.scss | |||
@@ -41,7 +41,7 @@ | |||
41 | ); | 41 | ); |
42 | 42 | ||
43 | @include assert-equal(iro-props-store($map), null, 'Save default tree'); | 43 | @include assert-equal(iro-props-store($map), null, 'Save default tree'); |
44 | @include assert-equal(iro-props-clear(), null, 'Delete default tree'); | 44 | @include assert-equal(iro-props-clear(), null, 'Delete default tree'); |
45 | } | 45 | } |
46 | 46 | ||
47 | @include it('Read') { | 47 | @include it('Read') { |
@@ -85,20 +85,20 @@ | |||
85 | @include assert-equal(iro-props-store($map3, 'namespaced'), null, 'Save "namespaced" tree'); | 85 | @include assert-equal(iro-props-store($map3, 'namespaced'), null, 'Save "namespaced" tree'); |
86 | } | 86 | } |
87 | 87 | ||
88 | @include assert-equal(iro-props-get(--background), map-get($map1, --background), 'Get --background in default'); | 88 | @include assert-equal(iro-props-get-static(--background), map-get($map1, --background), 'Get --background in default'); |
89 | @include assert-equal(iro-props-get(--buttons --primary --background), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get --buttons --primary --background in default'); | 89 | @include assert-equal(iro-props-get-static(--buttons --primary --background), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get --buttons --primary --background in default'); |
90 | @include assert-equal(iro-props-get(--box, $default: false), false, 'Get nonexistent in default'); | 90 | @include assert-equal(iro-props-get-static(--box, $default: false), false, 'Get nonexistent in default'); |
91 | 91 | ||
92 | @include assert-equal(iro-props-get(--background, 'test'), map-get($map2, --background), 'Get --background in "test"'); | 92 | @include assert-equal(iro-props-get-static(--background, 'test'), map-get($map2, --background), 'Get --background in "test"'); |
93 | @include assert-equal(iro-props-get(--buttons --primary --background, 'test'), map-get(map-get(map-get($map2, --buttons), --primary), --background), 'Get --buttons --primary --background in "test"'); | 93 | @include assert-equal(iro-props-get-static(--buttons --primary --background, 'test'), map-get(map-get(map-get($map2, --buttons), --primary), --background), 'Get --buttons --primary --background in "test"'); |
94 | @include assert-equal(iro-props-get(--box, 'test', $default: false), false, 'Get nonexistent in "test"'); | 94 | @include assert-equal(iro-props-get-static(--box, 'test', $default: false), false, 'Get nonexistent in "test"'); |
95 | 95 | ||
96 | @include assert-equal(iro-props-get(--background, 'namespaced', $default: false), false, 'Get --background in "namespaced"'); | 96 | @include assert-equal(iro-props-get-static(--background, 'namespaced', $default: false), false, 'Get --background in "namespaced"'); |
97 | @include assert-equal(iro-props-get(--ns --background, 'namespaced'), map-get($map3, --background), 'Get --ns --background in "namespaced"'); | 97 | @include assert-equal(iro-props-get-static(--ns --background, 'namespaced'), map-get($map3, --background), 'Get --ns --background in "namespaced"'); |
98 | @include iro-props-namespace('ns') { | 98 | @include iro-props-namespace('ns') { |
99 | @include assert-equal(iro-props-get(--background, 'namespaced'), map-get($map3, --background), 'Get namespaced --background in "namespaced"'); | 99 | @include assert-equal(iro-props-get-static(--background, 'namespaced'), map-get($map3, --background), 'Get namespaced --background in "namespaced"'); |
100 | @include assert-equal(iro-props-get(--buttons --primary --background, 'namespaced'), map-get(map-get(map-get($map3, --buttons), --primary), --background), 'Get namespaced --buttons --primary --background in "namespaced"'); | 100 | @include assert-equal(iro-props-get-static(--buttons --primary --background, 'namespaced'), map-get(map-get(map-get($map3, --buttons), --primary), --background), 'Get namespaced --buttons --primary --background in "namespaced"'); |
101 | @include assert-equal(iro-props-get(--box, 'namespaced', $default: false), false, 'Get namespaced nonexistent in "namespaced"'); | 101 | @include assert-equal(iro-props-get-static(--box, 'namespaced', $default: false), false, 'Get namespaced nonexistent in "namespaced"'); |
102 | } | 102 | } |
103 | 103 | ||
104 | @include assert-equal(iro-props-clear(), null, 'Delete default tree'); | 104 | @include assert-equal(iro-props-clear(), null, 'Delete default tree'); |
@@ -130,10 +130,10 @@ | |||
130 | @include assert-equal(iro-props-store($map1), null, 'Save default tree'); | 130 | @include assert-equal(iro-props-store($map1), null, 'Save default tree'); |
131 | @include assert-equal(iro-props-store($map2, $merge: true), null, 'Overwrite default tree'); | 131 | @include assert-equal(iro-props-store($map2, $merge: true), null, 'Overwrite default tree'); |
132 | 132 | ||
133 | @include assert-equal(iro-props-get(), iro-map-merge-recursive($map1, $map2), 'After update, get whole map'); | 133 | @include assert-equal(iro-props-get-static(), iro-map-merge-recursive($map1, $map2), 'After update, get whole map'); |
134 | @include assert-equal(iro-props-get(--background), map-get($map2, --background), 'After update, get --background'); | 134 | @include assert-equal(iro-props-get-static(--background), map-get($map2, --background), 'After update, get --background'); |
135 | @include assert-equal(iro-props-get(--text), map-get($map2, --text), 'After update, get --text'); | 135 | @include assert-equal(iro-props-get-static(--text), map-get($map2, --text), 'After update, get --text'); |
136 | @include assert-equal(iro-props-get(--buttons --primary --text), map-get(map-get(map-get($map1, --buttons), --primary), --text), 'After update, get --buttons --primary --text'); | 136 | @include assert-equal(iro-props-get-static(--buttons --primary --text), map-get(map-get(map-get($map1, --buttons), --primary), --text), 'After update, get --buttons --primary --text'); |
137 | 137 | ||
138 | @include assert-equal(iro-props-clear(), null, 'Delete default tree'); | 138 | @include assert-equal(iro-props-clear(), null, 'Delete default tree'); |
139 | } | 139 | } |
@@ -158,7 +158,7 @@ | |||
158 | @include iro-props-store($map); | 158 | @include iro-props-store($map); |
159 | 159 | ||
160 | @include output { | 160 | @include output { |
161 | @include iro-props-assign-native; | 161 | @include iro-props-assign; |
162 | } | 162 | } |
163 | 163 | ||
164 | @include expect { | 164 | @include expect { |
@@ -177,7 +177,7 @@ | |||
177 | @include iro-props-store($map); | 177 | @include iro-props-store($map); |
178 | 178 | ||
179 | @include output { | 179 | @include output { |
180 | @include iro-props-assign-native($skip: --buttons); | 180 | @include iro-props-assign($skip: --buttons); |
181 | } | 181 | } |
182 | 182 | ||
183 | @include expect { | 183 | @include expect { |
@@ -194,7 +194,7 @@ | |||
194 | } | 194 | } |
195 | 195 | ||
196 | @include output { | 196 | @include output { |
197 | @include iro-props-assign-native; | 197 | @include iro-props-assign; |
198 | } | 198 | } |
199 | 199 | ||
200 | @include expect { | 200 | @include expect { |
@@ -228,12 +228,12 @@ | |||
228 | 228 | ||
229 | @include assert-equal(iro-props-store($map), null, 'Save default tree'); | 229 | @include assert-equal(iro-props-store($map), null, 'Save default tree'); |
230 | 230 | ||
231 | @include assert-equal(iro-props-get-native(--background), var(--background), 'Get --background'); | 231 | @include assert-equal(iro-props-get(--background), var(--background), 'Get --background'); |
232 | @include assert-equal(iro-props-get-native(--buttons --primary --text), var(--buttons--primary--text), 'Get --buttons --primary --text'); | 232 | @include assert-equal(iro-props-get(--buttons --primary --text), var(--buttons--primary--text), 'Get --buttons --primary --text'); |
233 | @include assert-equal(iro-props-get-native(--buttons --secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get --buttons --secondary --text with default'); | 233 | @include assert-equal(iro-props-get(--buttons --secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get --buttons --secondary --text with default'); |
234 | @include iro-props-namespace('buttons') { | 234 | @include iro-props-namespace('buttons') { |
235 | @include assert-equal(iro-props-get-native(--primary --text), var(--buttons--primary--text), 'Get via namespace "buttons" --primary --text'); | 235 | @include assert-equal(iro-props-get(--primary --text), var(--buttons--primary--text), 'Get via namespace "buttons" --primary --text'); |
236 | @include assert-equal(iro-props-get-native(--secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get via namespace "buttons" --secondary --text with default'); | 236 | @include assert-equal(iro-props-get(--secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get via namespace "buttons" --secondary --text with default'); |
237 | } | 237 | } |
238 | 238 | ||
239 | @include assert-equal(iro-props-clear(), null, 'Delete default tree'); | 239 | @include assert-equal(iro-props-clear(), null, 'Delete default tree'); |
@@ -264,16 +264,16 @@ | |||
264 | @include assert-equal(iro-props-store($map1), null, 'Save default tree'); | 264 | @include assert-equal(iro-props-store($map1), null, 'Save default tree'); |
265 | @include assert-equal(iro-props-store($map2, 'second'), null, 'Save "second" tree'); | 265 | @include assert-equal(iro-props-store($map2, 'second'), null, 'Save "second" tree'); |
266 | 266 | ||
267 | @include assert-equal(iro-props-get(--buttons --primary --background, 'second'), map-get($map1, --background), 'Get referenced value'); | 267 | @include assert-equal(iro-props-get-static(--buttons --primary --background, 'second'), map-get($map1, --background), 'Get referenced value'); |
268 | @include assert-equal(iro-props-get-native(--buttons --primary --background, 'second'), var(--buttons--primary--background), 'Get referenced value, native'); | 268 | @include assert-equal(iro-props-get(--buttons --primary --background, 'second'), var(--buttons--primary--background), 'Get referenced value, native'); |
269 | 269 | ||
270 | @include assert-equal(iro-props-get(--buttons --default, 'second'), map-get(map-get($map1, --buttons), --primary), 'Get referenced subtree, whole'); | 270 | @include assert-equal(iro-props-get-static(--buttons --default, 'second'), map-get(map-get($map1, --buttons), --primary), 'Get referenced subtree, whole'); |
271 | @include assert-equal(iro-props-get(--buttons --default --background, 'second'), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get referenced subtree, inner value'); | 271 | @include assert-equal(iro-props-get-static(--buttons --default --background, 'second'), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get referenced subtree, inner value'); |
272 | @include assert-equal(iro-props-get-native(--buttons --default --background, 'second'), var(--buttons--default--background), 'Get referenced subtree, native'); | 272 | @include assert-equal(iro-props-get(--buttons --default --background, 'second'), var(--buttons--default--background), 'Get referenced subtree, native'); |
273 | 273 | ||
274 | @include assert('Native assignment') { | 274 | @include assert('Native assignment') { |
275 | @include output { | 275 | @include output { |
276 | @include iro-props-assign-native('second'); | 276 | @include iro-props-assign('second'); |
277 | } | 277 | } |
278 | 278 | ||
279 | @include expect { | 279 | @include expect { |