Class: NfgUi::Components::Elements::Avatar

Inherits:
Base show all
Includes:
Bootstrap::Utilities::Sizable, Bootstrap::Utilities::Tooltipable, Bootstrap::Utilities::Wrappable, Traits::Size
Defined in:
lib/nfg_ui/components/elements/avatar.rb

Overview

Activity doc coming soon

Constant Summary

Constants included from Traits::Size

Traits::Size::TRAITS

Constants included from Traits

Traits::REGISTERED_TRAITS, Traits::TRAIT_MODULES

Instance Attribute Summary

Attributes included from Bootstrap::Utilities::Wrappable

#as

Attributes included from Bootstrap::Utilities::Disableable

#as

Attributes inherited from Bootstrap::Components::Base

#body, #options, #view_context

Instance Method Summary collapse

Methods included from Traits::Size

#lg_trait, #md_trait, #sm_trait, #xl_trait

Methods included from Bootstrap::Utilities::Wrappable

#utility_initialize

Methods included from Bootstrap::Utilities::Tooltipable

#data, #disabled_component_tooltip_wrapper_html_options, #html_options, #tooltip

Methods included from Bootstrap::Utilities::Disableable

#disabled

Methods included from Utilities::Traitable

#traits, #utility_initialize

Methods included from Utilities::Renderable

#render_if, #render_unless

Methods included from Utilities::Describable

#data, #describe

Methods inherited from Bootstrap::Components::Base

#component_family, #data, #href, #html_options, #id, #initialize, #style

Constructor Details

This class inherits a constructor from NfgUi::Bootstrap::Components::Base

Instance Method Details

#altObject



13
14
15
# File 'lib/nfg_ui/components/elements/avatar.rb', line 13

def alt
  options.fetch(:alt, nil)
end

#imageObject



17
18
19
# File 'lib/nfg_ui/components/elements/avatar.rb', line 17

def image
  options.fetch(:image, nil)
end

#renderObject



21
22
23
24
25
26
27
28
29
# File 'lib/nfg_ui/components/elements/avatar.rb', line 21

def render
  (as, html_options) do
    if image.present?
      image_tag view_context.image_path(image), alt: alt.presence
    elsif body.present?
      (:span, (block_given? ? yield : body), class: body_css_class)
    end
  end
end

#sizeObject

Set the default size if no size is set. Avatars, unlike other components, always have a size provided to them. This also rejects nil from fetching as a fallback



35
36
37
# File 'lib/nfg_ui/components/elements/avatar.rb', line 35

def size
  options[:size] || default_size
end