automatically css sprite.
What css_sprite does?
css sprite generates css_sprite image and css files automatically for you follow the conventions as follows.
|images under css_sprite directory||class name in css_sprite css|
|widget/icons/twitter_icon.png||.widget .icons .twitter_icon|
css_sprite directory is the directory whose name is “css_sprite” or “css_sprite” suffixed under public/images directory.
css_sprite image is the image file automatically generated under public/images directory.
css_sprite css is the css file automatically generated under public/stylesheets directory.
css_sprite depends on the
rmagick gem, please make sure RMagick is successfully installed on your system.
css_sprite also depends on the
optipng tool as default image optimization, but you can use any other image optimization tool, check the Configuration section. If you use the default optipng tool, please make sure it is successfully installed on your system.
install css_sprite as a gem:
sudo gem install css_sprite
or install css_sprite as a plugin:
script/plugin install git://github.com/flyerhzm/css_sprite.git
1. create a directory whose name is css_sprite or ends with css_sprite (e.g. widget_css_sprite) under
2. if you install the css_sprite as a gem, you should add css_sprite task in Rakefile
If you install it as a plugin, you can skip this step
config/css_sprite.yml, it is not necessary by default.
3. start css_sprite server
4. put any images which you need to do the css sprite under the css_sprite directory, then you will see the automatically generated css sprite image and css files.
5. include the stylesheet in your view page
<%= stylesheet_link_tag 'css_sprite' %>
You can stop the css_sprite server by
You can restart the css_sprite server by
Or you can just do the css sprite manually by
There is no need to create any configuration by default. If you want some customizations as follows, you need to define
css_sprite use optipng with optimization level 2 to optimize the auto generated css_sprite image. You can change it to any image optimization command.
optimization: optipng -o 7
- For css
suffix: button: | text-indent: -9999px; display: block; cursor: pointer; font-size: 0; line-height: 15px; border: 0; outline: 0; icon: | text-indent: -9999px; cursor: pointer;
- For sass
engine: sass suffix: button: | text-indent: -9999px display: block cursor: pointer font-size: 0 line-height: 15px border: 0 outline: 0 icon: | text-indent: -9999px cursor: pointer
engine defines css (default) or sass file to generate.
suffix defines the customization styles for specified images.
The customization above means if your image filename is button suffixed (e.g. post_button.png), the corresponding class .post_button has the additional style with (outline: 0; border: 0; and so on),
if your image filename is icon suffixed (e.g. twitter_icon.png), the correspondiing class .twitter_icon has the additional style with (text-indent: -9999px; cursor: pointer)
Copyright © 2009 [Richard Huang (email@example.com)], released under the MIT license