Last active
August 29, 2015 14:05
-
-
Save whizark/9001629e7e2ab45e79a4 to your computer and use it in GitHub Desktop.
Sass: Map getter & overridding #sass
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
// ---- | |
// Sass (v3.4.1) | |
// Compass (v1.0.1) | |
// ---- | |
// A property map | |
$properties: ( | |
prop-1: "raw-prop-1-value", | |
prop-2: "raw-prop-2-value" | |
); | |
// The getter for the prop-1 property | |
@function get-prop-1($value) { | |
@return 'non-' + $value; | |
} | |
// The overridding function that calls a getter | |
@function get($properties, $key) { | |
$getter: "get-" + $key; | |
$value : map-get($properties, $key); | |
@if (function-exists($getter)) { | |
@return call($getter, $value); | |
} | |
@return $value; | |
} | |
// Test | |
.getter { | |
prop-1: get($properties, prop-1); | |
prop-2: get($properties, prop-2); | |
} |
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
.getter { | |
prop-1: "non-raw-prop-1-value"; | |
prop-2: "raw-prop-2-value"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment