Created
August 6, 2013 15:53
-
-
Save cahnory/6165793 to your computer and use it in GitHub Desktop.
Sort of sprintf for Sass
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
@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 | |
*/ |
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
@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