5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/initialjs-rails/view_helpers.rb', line 5
def avatar_image(avatarable, options = {})
size = options.fetch(:size, 100)
klass = options.fetch(:class, '')
round_corners = options.fetch(:round_corners, true)
seed = options.fetch(:seed, 0)
char_count = options.fetch(:count, 1)
txt_color = options.fetch(:color, '#ffffff')
bg_color = options.fetch(:background_color, nil)
initial_src = options.fetch(:src, '/assets/initialjs-blank.png')
name = options.fetch(:name, get_name_with_count(avatarable, char_count))
alt = options.fetch(:alt, get_name(avatarable))
radius = (size * 0.13).round if round_corners
font_size = (size * 0.6).round
data_attributes = {
'char-count' => char_count,
color: bg_color,
'font-size' => font_size,
height: size,
name: name,
radius: radius,
seed: seed,
'text-color' => txt_color,
width: size
}.reject { |_, v| v.blank? }
tag(:img, { alt: alt, class: "initialjs-avatar #{klass}".strip, data: data_attributes, src: initial_src }, true, false)
end
|