module Gravatarify

Provides support for adding gravatar images in ruby (and rails) applications.

Constants

GRAVATAR_ABBREV_OPTIONS

Hash of :ultra_long_option_name => :abbr_opt

VERSION

current API version, as defined by semver.org/

Public Class Methods

options() click to toggle source

Global options which are merged on every call to gravatar_url, this is useful to e.g. define a default image.

When using Rails defining default options is best done in an initializer config/initializers/gravatarify.rb (or similar).

Usage examples:

# set the default image using a Proc
Gravatarify.options[:default] = Proc.new { |*args| "http://example.com/avatar-#{args.first[:size] || 80}.jpg" }

# or set a custom default rating
Gravatarify.options[:rating] = :R

# or disable adding an extension
Gravatarify.options[:filetype] = false
# File lib/gravatarify.rb, line 30
def options; @options ||= { :filetype => :jpg } end
rails?() click to toggle source

Is running rails and at least rails 3.x

# File lib/gravatarify.rb, line 61
def rails?
  defined?(::Rails) && ::Rails.version.to_i >= 3
end
setup_rails!() click to toggle source

Loads ‘Gravatarify::Helper` as view helper via `ActionController::Base.helper`

# File lib/gravatarify.rb, line 66
def setup_rails!
  ActiveSupport.on_load(:action_controller) { ActionController::Base.helper(Gravatarify::Helper) }
end
styles() click to toggle source

Allows to define some styles, makes it simpler to call by name, instead of always giving a size etc.

Gravatarify.styles[:mini] => { :size => 30, :default => "http://example.com/gravatar-mini.jpg" }

# in the views, it will then use the stuff defined by styles[:mini]:
<%= gravatar_tag @user, :mini %>
# File lib/gravatarify.rb, line 39
def styles; @styles ||= {} end
subdomains=(subdomains) click to toggle source

Globally overide subdomains used to build gravatar urls, normally gravatarify picks from either 0.gravatar.com, 1.gravatar.com, 2.gravatar.com, 3.gravater.com or www.gravatar.com when building hosts, to use a custom set of subdomains (or none!) do something like:

Gravatarify.subdomains = %w{ 0 www } # only use 0.gravatar.com and www.gravatar.com
# File lib/gravatarify.rb, line 48
def subdomains=(subdomains) @subdomains = [*subdomains] end