Created
November 23, 2015 15:11
-
-
Save husa/3960155b261ee1e30160 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
// ---- | |
// libsass (v3.2.5) | |
// ---- | |
// from http://www.sitepoint.com/extra-map-functions-sass/ | |
/// jQuery-style extend function | |
/// About `map-merge()`: | |
/// * only takes 2 arguments | |
/// * is not recursive | |
/// @param {Map} $map - first map | |
/// @param {ArgList} $maps - other maps | |
/// @param {Bool} $deep - recursive mode | |
/// @return {Map} | |
@function map-extend($map, $maps.../*, $deep */) { | |
$last: nth($maps, -1); | |
$deep: $last == true; | |
$max: if($deep, length($maps) - 1, length($maps)); | |
// Loop through all maps in $maps... | |
@for $i from 1 through $max { | |
// Store current map | |
$current: nth($maps, $i); | |
// If not in deep mode, simply merge current map with map | |
@if not $deep { | |
$map: map-merge($map, $current); | |
} @else { | |
// If in deep mode, loop through all tuples in current map | |
@each $key, $value in $current { | |
// If value is a nested map and same key from map is a nested map as well | |
@if type-of($value) == "map" and type-of(map-get($map, $key)) == "map" { | |
// Recursive extend | |
$value: map-extend(map-get($map, $key), $value, true); | |
} | |
// Merge current tuple with map | |
$map: map-merge($map, ($key: $value)); | |
} | |
} | |
} | |
@return $map; | |
} | |
@mixin xy($map: (), $args...) { | |
$new: map-extend($map, $args...); | |
@each $prop, $val in $new { | |
#{$prop}: $val; | |
} | |
} | |
$some-global-color: tomato; | |
// this could be added manually or by "editor" | |
$element-core-custom: ( | |
font-weight: bold // extend with new property | |
); | |
$element-custom: ( | |
border: 10px solid green // override existing value | |
); | |
.Element { | |
@include xy(( | |
color: $some-global-color, // access global values, eg. branding colors | |
border: solid 1px black, | |
background: white | |
), | |
$element-core-custom, | |
$element-custom | |
); | |
} |
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
.Element { | |
color: tomato; | |
border: 10px solid green; | |
background: white; | |
font-weight: bold; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment