Skip to content

Instantly share code, notes, and snippets.

@corysimmons
Created April 7, 2015 00:27
Show Gist options
  • Save corysimmons/1f0fecbb6af5ca3d2f3b to your computer and use it in GitHub Desktop.
Save corysimmons/1f0fecbb6af5ca3d2f3b to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// libsass (v3.1.0)
// ----
/// Sass can't split strings natively. Thanks to @HugoGiraudel for https://github.com/at-import/SassyLists
@function sl-explode($string, $delimiter: '', $separator: "space") {
@if type-of($string) != "string" {
@warn "`sl-explode` function expecting a string; #{type-of($string)} given.";
@return null;
}
@if type-of($delimiter) != "string" {
@warn "`sl-explode` function expecting a string; #{type-of($delimiter)} given.";
@return null;
}
$result: ();
$length: str-length($string);
@if not index("space" "comma", $separator) {
$separator: "space";
}
@if str-length($delimiter) == 0 {
@for $i from 1 through $length {
$result: append($result, str-slice($string, $i, $i));
}
@return $result;
}
$running: true;
$remaining: $string;
@while $running {
$index: str-index($remaining, $delimiter);
@if not $index {
$running: false;
}
@else {
$slice: str-slice($remaining, 1, $index - 1);
$result: append($result, $slice, $separator);
$remaining: str-slice($remaining, $index + str-length($delimiter));
}
}
@return append($result, $remaining, $separator);
}
@mixin foo($fraction: '1/1', $cycle: nth(sl-explode($fraction, '/'), 2)) {
content: $cycle; // should get 1
}
html {
@include foo;
}
html {
content: ""; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment