grunt-spritesmith
Version:
Grunt task for converting a set of images into a spritesheet and corresponding CSS variables.
104 lines (90 loc) • 2.62 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;
*/
$fork_name = 'fork';
$fork_x = 64px;
$fork_y = 0px;
$fork_offset_x = -64px;
$fork_offset_y = 0px;
$fork_width = 32px;
$fork_height = 32px;
$fork_total_width = 96px;
$fork_total_height = 96px;
$fork_image = 'spritesheet.algorithm.png';
$fork = 64px 0px -64px 0px 32px 32px 96px 96px 'spritesheet.algorithm.png' 'fork';
$github_name = 'github';
$github_x = 32px;
$github_y = 32px;
$github_offset_x = -32px;
$github_offset_y = -32px;
$github_width = 32px;
$github_height = 32px;
$github_total_width = 96px;
$github_total_height = 96px;
$github_image = 'spritesheet.algorithm.png';
$github = 32px 32px -32px -32px 32px 32px 96px 96px 'spritesheet.algorithm.png' 'github';
$twitter_name = 'twitter';
$twitter_x = 0px;
$twitter_y = 64px;
$twitter_offset_x = 0px;
$twitter_offset_y = -64px;
$twitter_width = 32px;
$twitter_height = 32px;
$twitter_total_width = 96px;
$twitter_total_height = 96px;
$twitter_image = 'spritesheet.algorithm.png';
$twitter = 0px 64px 0px -64px 32px 32px 96px 96px 'spritesheet.algorithm.png' 'twitter';
$spritesheet_width = 96px;
$spritesheet_height = 96px;
$spritesheet_image = 'spritesheet.algorithm.png';
$spritesheet_sprites = $fork $github $twitter;
$spritesheet = 96px 96px 'spritesheet.algorithm.png' $spritesheet_sprites;
/*
The provided mixins are intended to be used with the array-like variables
.icon-home {
spriteWidth($icon_home)
}
.icon-email {
sprite($icon_email)
}
*/
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);
}
}
}