Created
October 18, 2014 01:51
-
-
Save aubricus/1ac226b4fbca8416c552 to your computer and use it in GitHub Desktop.
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
@function get($dict, $key, $default: false) { | |
/* a python-style "get" function to emulate dictionary access in scss | |
param: $dict the dict you'd like to 'get' from | |
param: $key the 'key' to access | |
param: $default a default value to return should the 'get' fail | |
see: | |
- http://bit.ly/1cPvYXx | |
- http://stackoverflow.com/a/11041421 | |
example: | |
// define a scss 'dictionary' | |
// note: 'key values' are seperated by a space ONLY | |
// note: 'key value' paris are separated by a comma | |
$colors : | |
white #fff, | |
black #000, | |
red #ff0000; | |
.foo { | |
color: get($colors, white); | |
} | |
.bar { | |
color: get($colors, missing-color, $default: #00ff00); | |
} | |
*/ | |
@each $item in $dict { | |
$index: index($item, $key); | |
@if $index { | |
$return: if($index == 1, 2, $index); | |
@return nth($item, $return); | |
} | |
} | |
@return $default; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has been replaced by maps, and map functions in SCSS; but I wanted to put this somewhere.