Created
October 19, 2015 10:03
-
-
Save IainIsCreative/741672eea0fb3068c7d2 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// libsass (v3.2.5) | |
// ---- | |
// Nested map example | |
$nested-map: ( | |
key-1: ( | |
deep-key-1: ( | |
deeper-key: true | |
), | |
deep-key-2: true | |
), | |
); | |
// map-fetch function to fetch nested keys | |
@function map-fetch($map, $keys) { | |
@each $key in $keys { | |
$map: map-get($map, $key); | |
} | |
@return if($map, true, false); | |
} | |
// nested fetch that directly fetches from $nested-map specifically | |
// $key references the | |
// | |
@function nested-fetch($key, $nested-key){ | |
$result: map-fetch($nested-map, $key $nested-key); | |
@return if($result, $result, 'null'); | |
} | |
$foo: nested-fetch(key-1, deep-key-1 deeper-key); | |
// returns null(??) | |
$bar: nested-fetch(key-1, deep-key-2); | |
// returns true | |
$baz: map-fetch($nested-map, key-1 deep-key-1 deeper-key); | |
.foo:before { | |
content: '' + $foo + ''; | |
} | |
.bar:after { | |
content: '' + $bar + ''; | |
} | |
.baz:after { | |
content: '' + $baz + ''; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.foo:before { | |
content: "null"; | |
} | |
.bar:after { | |
content: "true"; | |
} | |
.baz:after { | |
content: "true"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment