Skip to content

Instantly share code, notes, and snippets.

@benib
Created July 29, 2014 23:24
Show Gist options
  • Save benib/92b22ef0716d571d796a to your computer and use it in GitHub Desktop.
Save benib/92b22ef0716d571d796a to your computer and use it in GitHub Desktop.
Sass str-to-list function converts a string to a list
$selectorItems: str-to-list(#{&});
@each $selectorItem in $selectorItems {
@debug $selectorItem;
}
@function str-to-list($string, $separator: ' ', $startAt: 1) {
$workStr: str-slice($string,$startAt);
$list: ();
$indexOfFirstSpace: str-index($workStr,$separator);
@if $indexOfFirstSpace == null {
$list: ($workStr);
} @else {
$list: (str-slice($workStr, 1, $indexOfFirstSpace - 1));
$list: join($list,str-to-list($workStr, $startAt: $indexOfFirstSpace + 1));
}
@return $list;
}
@silvandiepen
Copy link

you've forgot the separator in the str-to-list when you call it at #9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment