GithubHelp home page GithubHelp logo

djtek / gravtastic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrislloyd/gravtastic

1.0 0.0 1.0 170 KB

Add Gravatars to your Rubies/Rails!

Home Page: http://chrislloyd.com.au/pages/lessons-in-software-design

gravtastic's Introduction

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

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.

gravtastic's People

Contributors

chrislloyd avatar gohanlon avatar jasoncheow avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.