Rake tasks are provided to quickly compile sprites for both desktop and mobile sites, provided that conventions are followed.
A single sprite should be represented by a directory in the images directory at app/assets/images/sprites/{sprite name}
. All .png
images within this directory can be expected to be compiled into that sprite.
The rake task to compile all sprites:
rake sprites
The rake tasks compile a sprite png in the app/assets/images/sprites
directory that matches the name of the folder containing the source images. It also creates an scss file defining the rules necessary to apply an individual sprite image. The scss file is generated at app/assets/stylesheets/sprites
and will have to have an import line added for it in the platform's root css file. Example: @import "sprites/core";
The rake task will also automatically squeeze compiled sprite images using pngquant as well as send them to ImageOptim, an app that compresses pngs. Both of these tools must be installed manually before running the sprite task.
Applying the sprites' CSS is an arbitrary matter once the sprite is generated. A sprite's rules can be inspected in its generated scss file, and the recommended method for applying a sprite to an element is to use the sass @extend directive:
div.some-element {
display: block;
text-indent: -9999px;
@extend .{sprite name}-sprite-{image name};
}
This example will automatically set the display and text-indent mode of the element (via to the .sprite-base class) and the width, height, and background rules for the element (via to the individual sprite class)
Spriteicorn, SpriteFairy, SuperSprite, Squirts