Module: Trestle::GravatarHelper

Defined in:
app/helpers/trestle/gravatar_helper.rb

Instance Method Summary collapse

Instance Method Details

#gravatar_image_tag(email, **options) ⇒ Object Also known as: gravatar

Returns a Gravatar image tag for a given email address. See docs.gravatar.com/api/avatars/images/ for available options.

In general, this should be wrapped in an avatar block to apply styling. This method is also aliased as ‘gravatar`.

email - Email address for Gravatar image; will be MD5-hashed to create the URL options - Options to pass to Gravatar API (as query string params)

Examples

<%= avatar { gravatar_image_tag(“[email protected]”) } %>

<%= avatar { gravatar_image_tag(“[email protected]”, size: 120, d: “retro”) } %>

Returns a HTML-safe String.



19
20
21
# File 'app/helpers/trestle/gravatar_helper.rb', line 19

def gravatar_image_tag(email, **options)
  image_tag(gravatar_image_url(email, **options))
end

#gravatar_image_url(email, **options) ⇒ Object

Returns a Gravatar image URL for a given email address. See docs.gravatar.com/api/avatars/images/ for available options.

email - Email address for Gravatar image; will be MD5-hashed to create the URL options - Options to pass to Gravatar API (as query string params)

Example

<%= gravatar_image_url(“[email protected]”, size: 120, d: “retro”) %>

Returns a HTML-safe String.



35
36
37
38
39
40
41
# File 'app/helpers/trestle/gravatar_helper.rb', line 35

def gravatar_image_url(email, **options)
  options = default_gravatar_options.merge(options)

  url = "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.to_s.downcase)}.png"
  url << "?#{options.to_query}" if options.any?
  url
end