flyerhzm
(flyerhzm)
September 30, 2009, 3:27am
1
Hi guys,
I have written a rails plugin/gem to generate css sprite image
automatically.
The project repository is here: http://github.com/flyerhzm/css_sprite
It is based on RMagick and you need only define a rule from what
source images to a destination image, as follows:
forum_icon_vertical.gif: # destination image file
sources: # source image file list
- good_topic.gif
- mid_topic.gif
- unread_topic.gif
- sticky_topic.gif
orient: vertical # composite gravity, vertical or horizontal
span: 20 # span of space between two images
Then run a rake task
rake css_sprite:build
So, you can see a forum_icon_vertical.gif generated in public/images
directory and a css sprite rule in tmp/css_sprite.css, as follows:
.good_topic
backgound: url('/images/forum_icon_vertical.gif') no-repeat 0px
0px
width: 20px
height: 19px
.mid_topic
backgound: url('/images/forum_icon_vertical.gif') no-repeat 0px
39px
width: 20px
height: 19px
.unread_topic
backgound: url('/images/forum_icon_vertical.gif') no-repeat 0px
78px
width: 19px
height: 18px
.sticky_topic
backgound: url('/images/forum_icon_vertical.gif') no-repeat 0px
116px
width: 19px
height: 18px
Hope you like it!
Richard Huang
11155
(-- --)
August 24, 2010, 3:01pm
2
flyerhzm wrote:
Hi guys,
I have written a rails plugin/gem to generate css sprite image
automatically.
The project repository is here: GitHub - flyerhzm/css_sprite: automatically css sprite
It is based on RMagick and you need only define a rule from what
# span of space between two images
Then run a rake task
rake css_sprite:build
.....
Richard Huang
Thanks a lot dude !!
Cool,
I have already cloned it!!!
I think this link you also referred to (about css sprite best practices ) is equally significant for most of us: http://www.huangzhimin.com/entries/190-css-sprite-best-practices
flyerhzm
(flyerhzm)
August 25, 2010, 2:29am
4
I'm glad you like this plugin, and I also write a similar post here,
http://rails-bestpractices.com/posts/43-use-css-sprite-automatically ,
so that you can post your comment about it. Thanks
11155
(-- --)
March 3, 2011, 2:55pm
5
flyerhzm wrote in post #855601:
Hi guys,
I have written a rails plugin/gem to generate css sprite image
automatically.
This is awesome! I'm really glad you are creating tools like this.
Just wanted to through out there that there is another gem that is
similar, active_assets, but it also creates the stylesheets!
Check it out at Github: GitHub - shwoodard/active_assets: A Railtie that provides a full asset management system, including support for development and deployment. It is designed to manage javascripts and stylesheets using a dsl and generates image sprites from a parallel dsl.
The latest releases only work with Rails 3, but if you need 2.3 support
use 0.3.x.
Cheers,
Sam