¶ ↑
DeprecatedThis gem was written a long time ago during the Rails 2 era - way before Sprockets came on to the scene.
I would suggest using the awesome spite-factory gem as a replacement..
github.com/jakesgordon/sprite-factory
¶ ↑
AutoSprite 1.1.3An easy, automated CSS image sprite creator. Ruby 1.9 and Rails 3.0 Compatible!
Suppose you have 10 images on your homepage. Rather than downloading 10 seperate images one at a time, 1 image is downloaded and we use CSS to show different parts of that image when we need to. This speeds up your page load time. It can be hard to manage this manually since you need to keep appending images to a sprite file and updating your css file with the correct offsets, etc. Auto Sprite lets you get back to more important things.
¶ ↑
Install-
Install auto_sprite and RMagick.
gem install RMagick auto_sprite
-
Edit your environement.rb add config.gem “auto_sprite”
¶ ↑
Usage-
Include the stylesheet in your layout:
<%= stylesheet_link_tag "auto_sprite" %>`
-
Create a directory called sprites in your images directory (e.g. RAILS_ROOT/public/images/sprites)
-
Put the images you want to link to in your public/images/sprites directory.
-
Use your images like you normally would:
<%= image_tag 'sprites/icon1.jpg' %> A :title can also be passed so your icons have tooltips: <%= image_tag "sprites/stuff.png", :title => "I like Ice Cream" %>
-
Reload after adding any new images to sprites/ and enjoy your now faster rendering website.
¶ ↑
Notes-
Animated images are not supported.
-
Any image format supported by RMagick should work.
-
Images of mixed sizes are not a problem.
-
Should auto_sprite be removed, your application still works!
¶ ↑
DetailsWhen rails starts, it checks whether or not the CSS or Sprite file is stale or missing.
If so, it will create:
RAILS_ROOT/public/stylesheets/auto_sprite.css RAILS_ROOT/public/images/auto_sprite.png
The image tag will automatically generate a div tag for any images located in the sprite directory.
<span class="_as_logo_png"></span> instead of <img src="/images/sprites/logo.png" />
Here is an exmplmple of the stylehseet that would be generated if you had two files face3.png and face4.png
._as_face3_png { background-position:0 0px; height:16px; width:16px; } ._as_face4_png{ background-position:0 -16px; height:16px; width:16px; } ._as_face3_png, ._as_face3_png { display:inline-block; background-image:url('/images/auto_sprite.png'); background-repeat:no-repeat; }
¶ ↑
Contact- Author
-
Stephen Blackstone ([email protected])
- Website
Copyright © 2010 Stephen Blackstone, released under the MIT license