Last active
August 29, 2015 14:10
-
-
Save jakob-e/64143f5242ee7a286d09 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com. http://sassmeister.com/gist/64143f5242ee7a286d09
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
| Arglist flexibility test | |
| URL: | |
| http://sassmeister.com/gist/64143f5242ee7a286d09 | |
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.7) | |
| // Compass (v1.0.1) | |
| // ---- | |
| // | |
| // Arglist flexibility test | |
| // | |
| @mixin size($arglist...) { | |
| // Map arglist keywords | |
| $map: keywords($arglist); | |
| // Map is empty | |
| @if inspect($map) == '()' { | |
| // Argument one is map | |
| @if type-of(nth($arglist, 1)) == map { | |
| $map: nth($arglist, 1); | |
| } | |
| // Argument one is list or value | |
| // Note! this will break if mixin expects first | |
| // regular argument to be a list | |
| @else { | |
| // Expected argument order | |
| $keys: width, height; | |
| $list: if(type-of(nth($arglist, 1)) == list, nth($arglist, 1), $arglist); | |
| @for $i from 1 through length($list){ | |
| $map:map-merge($map, (nth($keys, $i):nth($list, $i))); | |
| } | |
| } | |
| } | |
| $width : map-get($map, width); | |
| $height: map-get($map, height); | |
| // If omitted height will | |
| // default to width value | |
| $height: $width !default; | |
| width : $width; | |
| height: $height; | |
| } | |
| .keyword-arguments{ | |
| /* Only width */ | |
| @include size($width: width-value); | |
| /* Only height */ | |
| @include size($height: height-value); | |
| /* Normal order */ | |
| @include size($width: width-value, $height: height-value); | |
| /* Reversed order */ | |
| @include size($height: height-value, $width: width-value); | |
| } | |
| .map-arguments { | |
| /* Only width */ | |
| $map:(width: width-value); | |
| @include size($map); | |
| /* Only height */ | |
| $map:(width: width-value, height: height-value); | |
| @include size($map); | |
| /* Normal order */ | |
| $map:(width: width-value, height: height-value); | |
| @include size($map); | |
| /* Reversed order */ | |
| $map:(height: height-value, width: width-value); | |
| @include size($map); | |
| } | |
| .list-arguments { | |
| /* Only width */ | |
| $list: width-value; | |
| @include size($list); | |
| /* Comma */ | |
| $list: width-value, height-value; | |
| @include size($list); | |
| /* Space */ | |
| $list: width-value height-value; | |
| @include size($list); | |
| } | |
| .arguments { | |
| /* Only width */ | |
| @include size(width-value); | |
| /* Width and height */ | |
| @include size(width-value, height-value); | |
| } | |
| // ========================================================== | |
| // Functionalized version | |
| @function map-arguments($arglist,$keys){ | |
| $map: keywords($arglist); | |
| @if inspect($map)=='()' and length($arglist) > 0 { | |
| @if type-of(nth($arglist,1))==map{$map:nth($arglist,1);} | |
| @else {$list:if(type-of(nth($arglist,1))==list,nth($arglist,1),$arglist); | |
| @for $i from 1 through length($list){$map:map-merge($map,(nth($keys,$i):nth($list,$i)));} | |
| } | |
| } @return $map; | |
| } | |
| @mixin my-mixin($arglist...) { | |
| $map : map-arguments($arglist, (width, height)); | |
| $width : map-get($map, width); | |
| $height: map-get($map, height); | |
| $height: $width !default; | |
| width : $width; | |
| height : $height; | |
| } | |
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
| .keyword-arguments { | |
| /* Only width */ | |
| width: width-value; | |
| height: width-value; | |
| /* Only height */ | |
| height: height-value; | |
| /* Normal order */ | |
| width: width-value; | |
| height: height-value; | |
| /* Reversed order */ | |
| width: width-value; | |
| height: height-value; | |
| } | |
| .map-arguments { | |
| /* Only width */ | |
| width: width-value; | |
| height: width-value; | |
| /* Only height */ | |
| width: width-value; | |
| height: height-value; | |
| /* Normal order */ | |
| width: width-value; | |
| height: height-value; | |
| /* Reversed order */ | |
| width: width-value; | |
| height: height-value; | |
| } | |
| .list-arguments { | |
| /* Only width */ | |
| width: width-value; | |
| height: width-value; | |
| /* Comma */ | |
| width: width-value; | |
| height: height-value; | |
| /* Space */ | |
| width: width-value; | |
| height: height-value; | |
| } | |
| .arguments { | |
| /* Only width */ | |
| width: width-value; | |
| height: width-value; | |
| /* Width and height */ | |
| width: width-value; | |
| height: height-value; | |
| } |
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
| Arglist flexibility test | |
| URL: | |
| http://sassmeister.com/gist/64143f5242ee7a286d09 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment