Skip to content

Instantly share code, notes, and snippets.

@whizark
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whizark/9001629e7e2ab45e79a4 to your computer and use it in GitHub Desktop.
Save whizark/9001629e7e2ab45e79a4 to your computer and use it in GitHub Desktop.
Sass: Map getter & overridding #sass
// ----
// 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);
}
.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