Created
February 5, 2015 05:48
-
-
Save jednano/25b2a0d74d6d6e379b09 to your computer and use it in GitHub Desktop.
Auto Spriting
This file contains 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
$bem-blocks: ( | |
"foo", | |
"bar", | |
"baz" | |
); | |
$sprite-files: (); | |
/* | |
* Generate BEM-style silent classes for BEM sprites | |
* | |
* sprites/foo/ | |
* bar-baz.png | |
* qux.png | |
* | |
* Generates: %foo-sprites__bar-baz and %foo-sprites__qux | |
* Provides: width, height and background: <url> <position> no-repeat. | |
*/ | |
@each $block in $bem-blocks { | |
@if str-index($block, "_") { | |
@error "BEM sprite blocks must be dasherized."; | |
} | |
%#{$block}-sprites { | |
$map: sprite-map("sprites/#{$block}/*.png", $spacing: 10px); | |
// cache sprite-url, because it slows down compass compile | |
$url: sprite-url($map); | |
@each $name in sprite-names($map) { | |
@if str-index($name, "_") { | |
@error "BEM sprite files must be dasherized."; | |
} | |
$sprite-files: map-merge($sprite-files, ( | |
#{$block}-sprite__#{$name}: sprite-file($map, #{$name}) | |
)); | |
&__#{$name} { | |
background: $url sprite-position($map, $name) no-repeat; | |
@include sprite-dimensions($map, $name); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment