Created
April 20, 2014 13:11
-
-
Save pascalduez/11113860 to your computer and use it in GitHub Desktop.
Sass configurable _map-keys and _map-values functions.
This file contains 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
// ---- | |
// Sass (v3.3.5) | |
// Compass (v1.0.0.alpha.18) | |
// ---- | |
// Sass core function return comma separated lists. | |
// configurabele _map-keys and _map-values functions. | |
// Does not work with nested maps. (neither core). | |
// Returns a list of all keys in a map. | |
// -------------------------------------------------------------------------------- | |
// @param [map] $map | |
// @param [string] $separator: space | comma | auto | |
// -------------------------------------------------------------------------------- | |
// @return [list] | |
@function _map-keys($map, $separator: auto) { | |
$return: (); | |
@each $key, $value in $map { | |
$return: append($return, $key, $separator); | |
} | |
@return $return; | |
} | |
@function __map-keys($map, $separator: space) { | |
@return join((), map-keys($map), $separator); | |
} | |
// Returns a list of all values in a map. | |
// -------------------------------------------------------------------------------- | |
// @param [map] $map | |
// @param [string] $separator: space | comma | auto | |
// -------------------------------------------------------------------------------- | |
// @return [list] | |
@function _map-values($map, $separator: auto) { | |
$return: (); | |
@each $key, $value in $map { | |
$return: append($return, $value, $separator); | |
} | |
@return $return; | |
} | |
@function __map-values($map, $separator: space) { | |
@return join((), map-values($map), $separator); | |
} | |
sass { | |
$map: (one: 1px, two: 2px); | |
$test: (test: $map); | |
keys: _map-keys($map); | |
values: _map-values($map); | |
/* */ | |
keys: __map-keys($map); | |
values: __map-values($map); | |
// test: map-values($test); | |
} |
This file contains 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
sass { | |
keys: one two; | |
values: 1px 2px; | |
/* */ | |
keys: one two; | |
values: 1px 2px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment