Class: Fluxbit::GravatarComponent

Inherits:
AvatarComponent show all
Includes:
Config::AvatarComponent, Config::GravatarComponent
Defined in:
app/components/fluxbit/gravatar_component.rb

Overview

The ‘Fluxbit::GravatarComponent` is a component for rendering Gravatar avatars. It extends `Fluxbit::AvatarComponent` and provides options for configuring the Gravatar’s appearance and behavior. You can control the Gravatar’s rating, size, filetype, and other attributes.

The URL generation logic lives in ‘Fluxbit::Gravatar` and can be used standalone:

Fluxbit::Gravatar.url(email: "user@example.com")

Instance Method Summary collapse

Methods inherited from AvatarComponent

#avatar_itself, #declare_classes, #declare_color, #dot_indicator, #placeholder_icon, #placeholder_size

Methods inherited from Component

#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #icon, #options, #popover?, #random_id, #remove_class, #remove_class_from_props, #render_popover_or_tooltip, #target, #tooltip?

Methods included from IconHelpers

#chevron_double_left, #chevron_double_right, #chevron_down, #chevron_left, #chevron_right, #chevron_up, #close_icon, #ellipsis_horizontal, #eye_icon, #eye_slash_icon, #plus_icon

Constructor Details

#initialize(**props) ⇒ GravatarComponent

Initializes the Gravatar component with the given properties.

Parameters:

  • props (Hash)

    The properties to customize the Gravatar.

Options Hash (**props):

  • :email (String)

    The email address associated with the Gravatar.

  • :name (String)

    The display name for the Gravatar (used with :initials and :color defaults).

  • :initials (String)

    Custom initials to display (used with :initials default).

  • :rating (Symbol) — default: :g

    The rating of the Gravatar (:g, :pg, :r, :x).

  • :secure (Boolean) — default: true

    Whether to use HTTPS for the Gravatar URL.

  • :filetype (Symbol) — default: :png

    The filetype of the Gravatar (:png, :jpg, :gif).

  • :default (Symbol) — default: :identicon

    The default image to use if no Gravatar is found.

  • :size (Integer) — default: :md

    The size of the Gravatar base on the size provided by AvatarComponent.

  • :url_only (Boolean) — default: false

    If true, returns only the Gravatar URL instead of rendering the avatar component.

  • :remove_class (String) — default: ''

    Classes to be removed from the default Gravatar class list.

  • **props (Hash)

    Remaining options declared as HTML attributes, applied to the Gravatar container.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/components/fluxbit/gravatar_component.rb', line 30

def initialize(**props)
  @props = props
  @email = @props.delete(:email)
  @url_only = @props.delete(:url_only)

  @gravatar_url_options = {
    rating: @props.delete(:rating),
    secure: @props.delete(:secure),
    filetype: @props.delete(:filetype),
    default: @props.delete(:default),
    size: @props[:size],
    name: @props.delete(:name),
    initials: @props.delete(:initials)
  }.compact

  add class: gravatar_styles[:base], to: @props
  src = Fluxbit::Gravatar.url(email: @email, **@gravatar_url_options)
  super(src: src, **@props)
end

Instance Method Details

#callObject



50
51
52
53
# File 'app/components/fluxbit/gravatar_component.rb', line 50

def call
  return Fluxbit::Gravatar.url(email: @email, **@gravatar_url_options).html_safe if @url_only
  super
end