Module: GravatarHelper::PublicMethods

Included in:
ApplicationHelper
Defined in:
vendor/plugins/gravatar/lib/gravatar.rb

Overview

The methods that will be made available to your views.

Instance Method Summary

Instance Method Details

- (Object) gravatar(email, options = {})

Return the HTML img tag for the given email address’s gravatar.



48
49
50
51
52
53
# File 'vendor/plugins/gravatar/lib/gravatar.rb', line 48

def gravatar(, options={})
  src = h(gravatar_url(, options))
  options = DEFAULT_OPTIONS.merge(options)
  [:class, :alt, :size].each { |opt| options[opt] = h(options[opt]) }
  "<img class=\"#{options[:class]}\" alt=\"#{options[:alt]}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{src}\" />"      
end

- (Object) gravatar_api_url(hash, ssl = false)

Returns the base Gravatar URL for the given email hash. If ssl evaluates to true, a secure URL will be used instead. This is required when the gravatar is to be displayed on a HTTPS site.



58
59
60
61
62
63
64
# File 'vendor/plugins/gravatar/lib/gravatar.rb', line 58

def gravatar_api_url(hash, ssl=false)
  if ssl
    "https://secure.gravatar.com/avatar/#{hash}"
  else
    "http://www.gravatar.com/avatar/#{hash}"
  end
end

- (Object) gravatar_for(user, options = {})

Return the HTML img tag for the given user’s gravatar. Presumes that the given user object will respond_to "email", and return the user’s email address.



43
44
45
# File 'vendor/plugins/gravatar/lib/gravatar.rb', line 43

def gravatar_for(user, options={})
  gravatar(user., options)
end

- (Object) gravatar_url(email, options = {})

Return the gravatar URL for the given email address.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'vendor/plugins/gravatar/lib/gravatar.rb', line 67

def gravatar_url(, options={})
   = Digest::MD5.hexdigest()
  options = DEFAULT_OPTIONS.merge(options)
  options[:default] = CGI::escape(options[:default]) unless options[:default].nil?
  returning gravatar_api_url(, options.delete(:ssl)) do |url|
    opts = []
    [:rating, :size, :default].each do |opt|
      unless options[opt].nil?
        value = h(options[opt])
        opts << [opt, value].join('=')
      end
    end
    url << "?#{opts.join('&')}" unless opts.empty?
  end
end