Skip to content

Instantly share code, notes, and snippets.

@cahnory
Created August 6, 2013 15:53
Show Gist options
  • Save cahnory/6165793 to your computer and use it in GitHub Desktop.
Save cahnory/6165793 to your computer and use it in GitHub Desktop.
Sort of sprintf for Sass
@for $i from 1 through 12 {
@debug format(
('.on-', 2, '-columns-i-am-spanning-', 1),
(12, $i)
);
}
/*
DEBUG: .on-1-columns-i-am-spanning-12
DEBUG: .on-2-columns-i-am-spanning-12
[…]
DEBUG: .on-12-columns-i-am-spanning-12
*/
@function format($format, $args
// scope private var
,$_string: null
,$_token: null
) {
@each $_token in $format {
@if length($_token) > 1 {
$_token: format($_token, $args);
}
@else if type-of($_token) == number {
$_token: nth($args, $_token);
}
$_string: '#{$string}#{$_token}';
}
@return quote($_string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment