Skip to content

Instantly share code, notes, and snippets.

@KittyGiraudel
Created April 2, 2014 12:43
Show Gist options
  • Save KittyGiraudel/9933331 to your computer and use it in GitHub Desktop.
Save KittyGiraudel/9933331 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.3.4)
// Compass (v1.0.0.alpha.18)
// ----
//
// map-fetch($map, $keys)
//
// An easy way to fetch a deep value in a multi-level map. Works much like
// map-get() except that you pass multiple keys as the second parameter to
// go down multiple levels in the nested map.
@function map-fetch($map, $keys) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}
$config: (
themes: (
mist: (
header: #dcfac0,
content: #00968b,
footer: #85c79c
),
spring: (
header: #f4fac7,
content: #c2454e,
footer: #ffb158
)
)
);
@each $theme in map-keys(map-get($config, themes)) {
.#{$theme} {
.header { background-color: map-fetch($config, themes $theme header ); }
.content { background-color: map-fetch($config, themes $theme content ); }
.footer { background-color: map-fetch($config, themes $theme footer ); }
}
}
.mist .header {
background-color: #dcfac0;
}
.mist .content {
background-color: #00968b;
}
.mist .footer {
background-color: #85c79c;
}
.spring .header {
background-color: #f4fac7;
}
.spring .content {
background-color: #c2454e;
}
.spring .footer {
background-color: #ffb158;
}
@lunelson
Copy link

lunelson commented Apr 3, 2014

My map get works nearly the same, but with ($keys...) as the second argument so it's all comma-separated, rather than spaced (sass-list-maps)

@KittyGiraudel
Copy link
Author

Yeah, it's basically the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment