Module: MyGravatar::FormHelpers

Defined in:
lib/my_gravatar/form_helpers.rb

Instance Method Summary collapse

Instance Method Details

#gravatar_image_tag(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/my_gravatar/form_helpers.rb', line 4

def gravatar_image_tag(options = {})
  raise "Please specify gravatar options." unless options[:gravatar]
  raise "Please specify gravatar email." unless options[:gravatar][:email]

  source, options = process_gravatar_options(options)

  image_tag(source, options)
end

#process_gravatar_options(opts) ⇒ Object

secure, email, size, default_image, rating



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/my_gravatar/form_helpers.rb', line 14

def process_gravatar_options(opts)
  host = GravatarExtensions.url(opts[:gravatar][:secure] ||= false)
  hash = GravatarExtensions.(opts[:gravatar][:email])

  url_params = []
  ["size", "default_image", "rating"].each do |k|
    key = GravatarExtensions.gravatar_param_key(k)
    value = opts[:gravatar][k.to_sym] ||= GravatarExtensions.gravatar_default_value(k)
    url_params << "#{key}=#{value}" 
  end

  url = []
  url << host
  url << hash
  url << url_params.join("/")

  opts.delete(:gravatar) #remove the gravatar option

  return url.join("/"), opts
end