Module: LetterAvatar::AvatarHelper

Defined in:
lib/letter_avatar/avatar_helper.rb

Instance Method Summary collapse

Instance Method Details

#letter_avatar_for(name, size = 64) ⇒ Object



3
4
5
# File 'lib/letter_avatar/avatar_helper.rb', line 3

def letter_avatar_for(name, size = 64)
  LetterAvatar.generate(name, size)
end

#letter_avatar_tag(name, size = 64, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/letter_avatar/avatar_helper.rb', line 15

def letter_avatar_tag(name, size = 64, options = {})
  if defined?(ActionView::Helpers::AssetTagHelper)
    extend ActionView::Helpers::AssetTagHelper
    image_tag(letter_avatar_url(name, size), options.merge(alt: name))
  else
    "<img alt=\"#{name}\" class\"#{options.fetch(:class)}\" src=\"#{letter_avatar_url(name, size)}\" />"
  end
end

#letter_avatar_url(name, size = 64) ⇒ Object



11
12
13
# File 'lib/letter_avatar/avatar_helper.rb', line 11

def letter_avatar_url(name, size = 64)
  letter_avatar_url_for(letter_avatar_for(name, size))
end

#letter_avatar_url_for(avatar_path) ⇒ Object



7
8
9
# File 'lib/letter_avatar/avatar_helper.rb', line 7

def letter_avatar_url_for(avatar_path)
  avatar_path.to_s.sub('public/', '/')
end