Skip to content

Instantly share code, notes, and snippets.

@2no
Last active December 17, 2015 18:18
Show Gist options
  • Save 2no/5651894 to your computer and use it in GitHub Desktop.
Save 2no/5651894 to your computer and use it in GitHub Desktop.
Sass で sprintf。compass なら、config.rb に sprintf.rb の内容を書いておくと使える。
$tmp: "";
.sample1:after{
$tmp: sprintf("%02d,%02d", 1, 2);
content: "#{$tmp}";
}
// 結果:content: "01,02";
$tmp: "";
.sample1:after{
$tmp: sprintf("%.5s", foobar);
content: "#{$tmp}";
}
// 結果:content: "fooba";
require "sass"
module WakuworksFunctions
def sprintf(format, *args)
assert_type format, :String
assert_type args, :Array
Sass::Script::String.new(format.value%args)
end
end
module Sass::Script::Functions
include WakuworksFunctions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment