public
Description: A configurable and documented Rail view helper for adding gravatars into your Rails application
Homepage:
Clone URL: git://github.com/mdeering/gravatar_image_tag.git
README.textile

Gravatar Logo

Gravatar Image Tag Plugin

Rails view helper for grabbing Gravatar images. The goal here is to be configurable and have those configuration points documented!

Install as a Ruby on Rails Plugin

The traditional way.

./script/plugin install git://github.com/mdeering/gravatar_image_tag.git

or the old-school but still c00l way!

piston import git://github.com/mdeering/gravatar_image_tag.git vendor/plugins/gravatar_image_tag

or for all you hip gitsters.

git submodule add git://github.com/mdeering/gravatar_image_tag.git vendor/plugins/gravatar_image_tag git submodule init

Usage

Once you have installed it as a plugin for your rails app usage is simple.

gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering')

Boom here is my gravatar Michael Deering

Configuration Points

Setting the default image

If no default image is given in either an initializer or through the options passed to the gravatar_image_tag then the default image from the gravatar site will be displayed.

gravatar_image_tag('junk', :alt => 'Default Gravatar Image')

Splat the default gravatar image Default Gravatar Image

You can specify the default image through an initializer as follows:

# config/initializers/gravatar_defaults.rb
ActionView::Base.default_gravatar_image  = 'http://assets.yourhost.com/images/default_gravatar.png'

You can also specify the default image to fallback to or override the one set in the above initializer by passing the :gravatar => { :default => ‘http://assets.yourhost.com/images/override_gravatar.png’ } option to the gravatar_image_tag call. All other options will be forwarded onto the image_tag.

gravatar_image_tag('junk', :alt => 'Github Default Gravatar', :gravatar => { :default => 'http://github.com/images/gravatars/gravatar-80.png' })

Ka-Pow Github Default Gravatar

Setting the default image size

If no default image size is given in either the plugin configuration or through the options passed to the gravatar_image_tag then the default image size from the gravatar site will be displayed (80px x 80px at the time of this writing).

You can specify your default image size through the plugin configuration by adding the following line to your rails environment.

# config/initializers/gravatar_defaults.rb
ActionView::Base.default_gravatar_size  = 120

You can also specify the image size or override the one set in the plugin configuration by passing the :gravatar => { :size => 50 } option to the gravatar_image_tag call. All other options will be forwarded on to the image_tag call.

gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :class => 'some-class', :gravatar => { :size => 15 })

Mini Me! Michael Deering

Credits

The ideas an methods for this plugin are from expanding upon my original blog post Adding Gravatar To Your Website Or Blog

Copyright © 2009 Michael Deering, released under the MIT license