Skip to content

Instantly share code, notes, and snippets.

@mirisuzanne
Created October 13, 2014 16:49
Show Gist options
  • Save mirisuzanne/6edb61531d1dde365ba8 to your computer and use it in GitHub Desktop.
Save mirisuzanne/6edb61531d1dde365ba8 to your computer and use it in GitHub Desktop.
Map-push function (adds item to list in map)
// ----
// Sass (v3.4.5)
// Compass (v1.0.1)
// ----
// Initial hash
$hash: (
hello: world denver pittsburgh,
key: value list,
);
// Push Function
@function map-push($map, $key, $value) {
@return map-merge($map, ($key: append(map-get($hash, $key), $value)));
}
// Before
.hash-before {
@each $key, $value in $hash {
#{$key}: $value;
}
}
// Usage
$hash: map-push($hash, hello, texas);
// After
.hash-after {
@each $key, $value in $hash {
#{$key}: $value;
}
}
.hash-before {
hello: world denver pittsburgh;
key: value list;
}
.hash-after {
hello: world denver pittsburgh texas;
key: value list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment