Last active
April 3, 2016 07:56
-
-
Save mistergraphx/2ae5071eaf1b9581def5 to your computer and use it in GitHub Desktop.
map-isset() testing tool for maps - 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) | |
// ---- | |
/* @function map-isset() | |
Sometimes we need to test if a map is really set. | |
Testing with variable_exist is not enought, cause if map is empty it return true | |
Type-of return false if the map is empty | |
For example in my icon-set component | |
https://gist.github.com/mistergraphx/dfc1c57bd7d202bf1464 | |
, the theme _globals must define a icon-set variable map containing : | |
$icon-set: ( | |
'icon': 'hex code' | |
); | |
@author - Arnaud B. (Mist. GraphX) | |
@url - http://www.mister-graphx.com | |
@see - http://sass-lang.com/documentation/Sass/Script/Functions.html | |
@param $input - | |
@return - what you want ;-) sting or boolean | |
*/ | |
$string-variable: "I'm a String"; | |
$empty-map-variable: (); | |
$filled-map-variable: ( | |
'key':'value' | |
); | |
@function map-isset($input){ | |
// Is it a map type variable ? | |
// Type-of() return false if the map is empty | |
// so we convert the number of keys to a list | |
// and use lenght to test the number of keys | |
@if((type-of($input) == 'map') and (length(map-keys($input)) > 0)){ | |
$num-of-keys: length(map-keys($input)); | |
@return "This is a map with " + $num-of-keys + "index set"; | |
} | |
@else { | |
@return "Hey your variable is not a map or there is no key, value defined"; | |
} | |
} | |
.selector { | |
color: map-isset($string-variable); | |
color: map-isset($empty-map-variable); | |
color: map-isset($filled-map-variable); | |
} |
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
/* @function map-isset() | |
Sometimes we need to test if a map is really set. | |
Testing with variable_exist is not enought, cause if map is empty it return true | |
Type-of return false if the map is empty | |
For example in my icon-set component | |
https://gist.github.com/mistergraphx/dfc1c57bd7d202bf1464 | |
, the theme _globals must define a icon-set variable map containing : | |
$icon-set: ( | |
'icon': 'hex code' | |
); | |
@author - Arnaud B. (Mist. GraphX) | |
@url - http://www.mister-graphx.com | |
@see - http://sass-lang.com/documentation/Sass/Script/Functions.html | |
@param $input - | |
@return - what you want ;-) sting or boolean | |
*/ | |
.selector { | |
color: "Hey your variable is not a map or there is no key, value defined"; | |
color: "Hey your variable is not a map or there is no key, value defined"; | |
color: "This is a map with 1index set"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment