Module: BoringAvatars::Bindings::Rails::ViewHelper

Defined in:
lib/boring_avatars/bindings/rails/view_helper.rb,
sig/boring_avatars.rbs

Instance Method Summary collapse

Instance Method Details

#boring_avatar(name, variant: :marble, colors: UNSPECIFIED, size: "40px", square: false, title: false, id_prefix: nil, **svg_attributes) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/boring_avatars/bindings/rails/view_helper.rb', line 11

def boring_avatar(
  name,
  variant: :marble,
  colors: UNSPECIFIED,
  size: "40px",
  square: false,
  title: false,
  id_prefix: nil,
  **svg_attributes
)
  prefix = id_prefix || "ba-#{SecureRandom.hex(10)}"
  options = {
    variant: variant,
    size: size,
    square: square,
    title: title,
    id_prefix: prefix,
    attributes: normalize_boring_avatar_attributes(svg_attributes)
  }
  options[:colors] = colors unless colors.equal?(UNSPECIFIED)

  svg = BoringAvatars.generate(name, **options)
  svg.html_safe
end