Skip to content

Instantly share code, notes, and snippets.

@una
Created November 27, 2014 13:48
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 una/dd7ec4d12b3cca6c1487 to your computer and use it in GitHub Desktop.
Save una/dd7ec4d12b3cca6c1487 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
Arglist flexibility test
URL:
http://sassmeister.com/gist/64143f5242ee7a286d09
// ----
// 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)=='()'{
@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;
}
.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;
}
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