Skip to content

Instantly share code, notes, and snippets.

@Undistraction
Last active August 29, 2015 14:06
Show Gist options
  • Save Undistraction/681818d751b6dd06c0cc to your computer and use it in GitHub Desktop.
Save Undistraction/681818d751b6dd06c0cc to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.3)
// Compass (v1.0.1)
// Sassy Maps (v0.4.0)
// ----
@import "sassy-maps";
$map-1:(
alpha: 1,
beta: 1,
charlie:(
delta: 1,
echo: 1,
foxtrot:(
gamma: 1,
hotel: 1
)
)
);
$map-2:(
alpha: 2,
charlie: (
echo: 2,
foxtrot: (
hotel: 2,
yankee:(
omega: 2
)
)
),
indigo: (
juliette: 2
)
);
// Note that these maps are merged to:
// (
// alpha: 2,
// beta: 1,
// charlie: (
// delta: 1,
// echo: 2,
// foxtrot: (
// gamma: 1,
// hotel: 2,
// yankee: (
// omega: 2
// ),
// indigo: (
// juliette: 2
// )
// )
// )
@function map-merge-deep($map-old, $map-new, $overwrite: true){
// Iterate through each value of the new map
@each $key, $new-value in $map-new {
// Check if that value already exists on the old map
@if map-has-key($map-old, $key) {
$old-value: map-get($map-old, $key);
$new-value-is-map: type-of($new-value) == map;
$old-value-is-map: type-of($old-value) == map;
// If both are maps, recurse regardless of $overwrite
@if $old-value-is-map and $new-value-is-map {
$merged-value: map-merge-deep($old-value, $new-value);
$map-old: map-set($map-old, $key, $merged-value);
}@else{
// Otherwise check $overwrite
@if $overwrite{
$map-old: map-set($map-old, $key, $new-value);
}
}
// There is no existing key so add
}@else{
$map-old: map-set($map-old, $key, $new-value);
}
}
@return $map-old
}
@mixin merge{
$map-1: map-merge-deep($map-1, $map-2) !global;
// content: "#{inspect($map-1)}";
$value: map-get-deep($map-1, charlie, foxtrot, hotel);
content: "#{map-to-string($map-1)}";
}
h5::after
{
@include merge;
}
h5::after {
content: "(alpha: 2, beta: 1, charlie: ((delta: 1, echo: 2, foxtrot: ((gamma: 1, hotel: 2, yankee: ((omega: 2)))))), indigo: ((juliette: 2)))";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment