negonicrac / gravtastic forked from chrislloyd/gravtastic
- Source
- Commits
- Network (12)
- Issues (0)
- Downloads (3)
- Wiki (1)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Fri Aug 29 22:53:00 -0700 2008 | |
| |
LICENSE | Sun Jun 08 17:36:03 -0700 2008 | |
| |
README.textile | ||
| |
Rakefile | Sat Aug 30 05:16:46 -0700 2008 | |
| |
bugs/ | Sat Aug 30 05:16:46 -0700 2008 | |
| |
gravtastic.gemspec | Sat Aug 30 05:16:46 -0700 2008 | |
| |
lib/ | Sat Aug 30 05:09:49 -0700 2008 | |
| |
spec/ | Sat Aug 30 04:37:26 -0700 2008 |
Easily add Gravatars to your Ruby objects.
Install
sudo gem install gravtasticUsage
Raw Ruby
Just add
require ‘gravtastic’In somewhere in your application and
include Gravtastic::ResourceBefore is_gravtastic.
Rails
In Rails >= 2.1 you can add a dependency gem dependency for Gravtastic. At yours environment.rb, add:
config.gem ‘gravtastic’Merb & DataMapper
If you are using Merb & DataMapper you can add do the same by adding the following to your init.rb file:
dependency ‘gravtastic’Make sure you add this after either the use_orm :datamapper line or after a DataMapper extension.
Models
The next step is to give your model a Gravatar.
Raw Ruby
class User include Gravtastic::Resource is_gravtastic :with => :email endRails & Merb
class User is_gravtastic endThis 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:
Now, you can access your object’s gravatar with the gravatar_url method:
Note that it defaults to a PG rating. You can specify extra options with a hash:
current_user.gravatar_url(:rating => ‘R’, :size => 512) => “http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=R18&s=512” current_user.gravatar_url(:secure => true) => “https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG”However, to DRY things up you can specify defaults in the class declaration.
is_gravtastic :with => :author_email, :rating => ‘R’, :size => 20Nice, now all the calls to gravatar_url will have the defaults you have specified. Any options that you pass when you use gravatar_url will over-ride these class-defaults.
PS. Bonus points for anybody who can tell me what that users email is!
Authors
- Chris Lloyd
- You
Contribute
You can checkout the source or fork it yourself from Github.
git clone git://github.com/chrislloyd/gravtastic.gitIf you submit a successful patch then you’ll be given full commit rights to the project.
Thanks
- Xavier Shay and others for Enki (the reason this was written)
- Matthew Moore for helpful suggestions and for submitting it to the official list of Gravatar implementations.
- Vincent Charles For an updated README.
License
Copyright © 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.

