Gravatar Helper - aadlani/nanoc-toolbox GitHub Wiki

http://rubydoc.info/github/aadlani/nanoc-toolbox/Nanoc/Toolbox/Helpers/Gravatar

Setup

In the folder lib/helpers_.rb add the Helper inclusion as following:

# Helpers of the nanoc-toolbox
include Nanoc::Toolbox::Helpers::Gravatar

Usage

Gravatar Image

This functions generates an image tag for the supplied email, with the specified options. So if you want the 100px Gravatar of [email protected], you should write in your view:

gravatar_image('[email protected]', :size => "100")

This code will generate the following HTML code:

<img src="http://gravatar.com/avatar/4d076af1db60b16e1ce080505baf821c?size=100" />

Gravatar Url

If you need only the URL of the image to link to it, or to render in a markdown/textile file, you could use gravatar_url:

gravatar_url('[email protected]', :size => "64", :ext => true)

It will return the following Gravatar URL

http://gravatar.com/avatar/4d076af1db60b16e1ce080505baf821c.jpg?size=64

Which corresponds to this image:

Gravatar

Example

Here is an example that use the URL and the image functions:

<a href="<%= gravatar_url('[email protected]', :size => "512") %>" title="Anouar's Gravatar">
  <%= gravatar_image('[email protected]', :size => "100", :alt => "Anouar ADLANI") %>
</a>