github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

chrislloyd / gravtastic

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 230
    • 13
  • Source
  • Commits
  • Network (13)
  • Issues (0)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (4)
    • v2.2.0
    • 1.5.2
    • 1.5.1
    • 1.5.0
Sending Request…
Click here to lend your support to: gravtastic and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Add Gravatars to your Rubies/Rails! — Read more

  cancel

http://chrislloyd.com.au/articles/lessons-in-software-design

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Remove license, credit Jeff. 
chrislloyd (author)
Sat Jan 02 15:20:02 -0800 2010
commit  91ac96b424c0b3565090252aed67401e76162e56
tree    7186641af70f7310dc40f6cdec0db040040c5c2a
parent  bf2ec740b8f23ad28c68e185b033d943b2e8d893
gravtastic /
name age
history
message
file .gitignore Thu Apr 30 17:22:40 -0700 2009 New version, new README. [chrislloyd]
file README.md Sat Jan 02 15:20:02 -0800 2010 Remove license, credit Jeff. [chrislloyd]
file Rakefile Sat Jan 02 15:12:47 -0800 2010 Switched from MG to Jeweller. [chrislloyd]
file VERSION Sat Jan 02 15:12:47 -0800 2010 Switched from MG to Jeweller. [chrislloyd]
directory lib/ Sat Jan 02 15:12:47 -0800 2010 Switched from MG to Jeweller. [chrislloyd]
directory spec/ Sat Jan 02 15:12:47 -0800 2010 Switched from MG to Jeweller. [chrislloyd]
README.md

Gravtastic

The super fantastic way of getting Gravatars. By Chris.

In less than 5 minutes you can add Gravatars to your Ruby project. It works in Rails, Merb and plain ol' Ruby.

The best way to learn more about Gravtastic is to look at the source. It's one file, about 80 LOC and really pretty simple. If that isn't for you, then follow the instructions below!

Install

sudo gem install gravtastic

Usage

Add this to your environment.rb:

config.gem 'gravtastic', :version => '>= 2.1.0'

Next, say that you want a Gravatar for your model:

class User < ActiveRecord::Base
  is_gravtastic!
end

And you are done! In your views you can now use the #gravatar_url method:

<%= image_tag @user.gravatar_url %>

If you want to change the image, you can do this:

<%= image_tag @user.gravatar_url(:rating => 'R', :secure => true) %>

That will show R rated Gravatars over a secure connection. If you find yourself repeating that all around your app, you can set the Gravatar defaults. In your model, just change the is_gravtastic! line to something like this:

is_gravtastic :author_email, :secure => true,
                             :filetype => :gif,
                             :size => 120

Now all your Gravatars will come from a secure connection, be a GIF and be 120x120px. The email will also come from the author_email field, not the default email field. Don't worry, you arn't locked into these defaults (you can override them by passing options to #gravatar_url like before).

Note: You can use either is_gravtastic! or is_gravtastic, they both do the same thing.

Plain Ruby

So you just have a regular ol' Ruby app? No Rails and ActiveRecord?

require 'gravtastic'
class BoringUser
  include Gravtastic
  is_gravtastic!
end

And wallah! That works exactly the same as in Rails! Now all instances of the BoringUser class will have #gravatar_url methods.

Note: the #gravatar_url methods don't get included until you specify the class is_gravtastic!

Complete List of Options

Option Description Default Values
secure Gravatar transmitted with SSL false true/false
size The size of the image 80 1..512
default The default avatar image none Any URL, or "identicon", "monsterid", "wavatar"
rating The lowest level of ratings you want to allow G G, PG, R or X
filetype The filetype of the image png gif, jpg or png

Making Changes Yourself

Fork the project, submit a pull request and I'll get to it straight away. Or you can just view the source like:

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

Thanks

  • Xavier Shay and others for Enki (the reason this was originally written)
  • Matthew Moore
  • Vincent Charles
  • Paul Farnell
  • Jeff Kreeftmeijer

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.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server