grunt-spritesmith
Version:
Grunt task for converting a set of images into a spritesheet and corresponding CSS variables.
119 lines (100 loc) • 2.78 kB
text/stylus
/*
Stylus variables are information about icon's compiled state, stored under its original file name
.icon-home {
width: $icon_home_width;
}
The large array-like variables contain all information about a single icon
$icon_home = x y offset_x offset_y width height total_width total_height image_path;
At the bottom of this section, we provide information about the spritesheet itself
$spritesheet = width height image $spritesheet_sprites;
*/
$icon1_name = 'icon1';
$icon1_x = 0px;
$icon1_y = 0px;
$icon1_offset_x = 0px;
$icon1_offset_y = 0px;
$icon1_width = 50px;
$icon1_height = 50px;
$icon1_total_width = 100px;
$icon1_total_height = 300px;
$icon1_image = 'sprite.cssVarMap.png';
$icon1 = 0px 0px 0px 0px 50px 50px 100px 300px 'sprite.cssVarMap.png' 'icon1';
$icon2_name = 'icon2';
$icon2_x = 0px;
$icon2_y = 50px;
$icon2_offset_x = 0px;
$icon2_offset_y = -50px;
$icon2_width = 50px;
$icon2_height = 50px;
$icon2_total_width = 100px;
$icon2_total_height = 300px;
$icon2_image = 'sprite.cssVarMap.png';
$icon2 = 0px 50px 0px -50px 50px 50px 100px 300px 'sprite.cssVarMap.png' 'icon2';
$icon3_name = 'icon3';
$icon3_x = 0px;
$icon3_y = 100px;
$icon3_offset_x = 0px;
$icon3_offset_y = -100px;
$icon3_width = 100px;
$icon3_height = 200px;
$icon3_total_width = 100px;
$icon3_total_height = 300px;
$icon3_image = 'sprite.cssVarMap.png';
$icon3 = 0px 100px 0px -100px 100px 200px 100px 300px 'sprite.cssVarMap.png' 'icon3';
$icons_width = 100px;
$icons_height = 300px;
$icons_image = 'sprite.cssVarMap.png';
$icons_sprites = $icon1 $icon2 $icon3;
$icons = 100px 300px 'sprite.cssVarMap.png' $icons_sprites;
/*
The provided mixins are intended to be used with the array-like variables
.icon-home {
spriteWidth($icon_home)
}
.icon-email {
sprite($icon_email)
}
Example usage in HTML:
`display: block` sprite:
<div class="icon-home"></div>
To change `display` (e.g. `display: inline-block;`), we suggest using a common CSS class:
// CSS
.icon {
display: inline-block;
}
// HTML
<i class="icon icon-home"></i>
*/
spriteWidth($sprite) {
width: $sprite[4];
}
spriteHeight($sprite) {
height: $sprite[5];
}
spritePosition($sprite) {
background-position: $sprite[2] $sprite[3];
}
spriteImage($sprite) {
background-image: url($sprite[8]);
}
sprite($sprite) {
spriteImage($sprite)
spritePosition($sprite)
spriteWidth($sprite)
spriteHeight($sprite)
}
/*
The `sprites` mixin generates identical output to the CSS template
but can be overridden inside of Stylus
This must be run when you have at least 2 sprites.
If run with a single sprite, then there will be reference errors.
sprites($spritesheet_sprites);
*/
sprites($sprites) {
for $sprite in $sprites {
$sprite_name = $sprite[9];
.{$sprite_name} {
sprite($sprite);
}
}
}