A rails plugin to generate css sprite image automatically

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

flyerhzm wrote:

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

           # 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

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

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: http://bitly.com/eRTwU4

The latest releases only work with Rails 3, but if you need 2.3 support
use 0.3.x.

Cheers,
Sam

One more option https://github.com/hagenburger/lemonade :wink: