Skip to content

Add Gravatars to your Rubies/Rails (and now Javascript)!

Notifications You must be signed in to change notification settings

hanigamal/gravtastic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easily add "Gravatars":http://gravatar.com to your Ruby objects.


h2. Install

  sudo gem install chrislloyd-gravtastic --source=http://gems.github.com


h2. Usage

Somewhere in your application you need to @require 'gravtastic'@. In Rails >= 2.1 you can forego this and just add a dependency gem dependency for Gravtastic.

    config.gem 'gravtastic', :source => 'http://gems.github.com/'

The next step is to give your class (or model in Rails) a Gravatar:

  class User
    include Gravtastic::Model
    has_gravatar
  end
  
This defaults to looking for the gravatar ID on the @email@ method. So, if your @User@ has an @email@ then it will send that to Gravatar to get their picture. You can change the default gravatar source like this:

  has_gravatar :on => :author_email

Now, you can access your object's gravatar with the @gravatar_url@ method:

  >> current_user.gravatar_url
  => "http://www.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e"

and you can specify extra options with a hash:

  >> a.gravatar_url(:rating => 'PG', :size => 512)
  => "http://www.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e?rating=PG&size=512"

PS.  Bonus points for anybody who can tell me what that users email is!
PPS. Shame on Auttomatic for still using MD5!


h2. The Future

It isn't auto-included in ActiveRecord and Datamapper classes. When I fix this it means that you won't have to do the whole @include Gravtastic::Model@ thing for your models. You'll still, however, have to do that for standard Ruby classes.

Also, I want to add a set of default options to the class so that you don't have to do add @:rating => 'PG'@ to every Gravatar you use.

And lastly, the RDoc sucks, so that needs to be included.


h2. Authors

* "Chris Lloyd":http://chrislloyd.com.au
* You


h2. Contribute

You can checkout the source or fork it yourself from Github.

  git clone git://github.com/chrislloyd/gravtastic.git

If you submit a successful patch then you'll be given full commit rights to the project.


h2. Thanks

* "Xavier Shay":http://rhnh.net and others for "Enki":http://enkiblog.com (the reason this was written)


h2. License

Copyright (c) 2008 Chris Lloyd.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Add Gravatars to your Rubies/Rails (and now Javascript)!

Resources

Stars

Watchers

Forks

Packages

No packages published