Module: Trestle::AvatarHelper

Defined in:
app/helpers/trestle/avatar_helper.rb

Instance Method Summary collapse

Instance Method Details

#avatar(fallback: nil, **attributes, &block) ⇒ Object

Renders an avatar (or similar image) styled as a circle typically designed to represent a user (though not limited to that). The avatar helper accepts a block within which the image should be provided, which will be resized to fit.

fallback - Optional short text (2-3 characters) shown when no image is available attributes - Additional HTML attributes to add to the <div> tag

Examples

<%= avatar { image_tag("person.jpg") } %>

<%= avatar(fallback: "SP", class: "avatar-lg") { gravatar("[email protected]") } %>

<%= avatar(style: "--avatar-size: 3rem") { gravatar("[email protected]") }

Return the HTML div containing the avatar image.



19
20
21
22
23
24
# File 'app/helpers/trestle/avatar_helper.rb', line 19

def avatar(fallback: nil, **attributes, &block)
  tag.div(**default_avatar_options.merge(attributes)) do
    concat tag.span(fallback, class: "avatar-fallback") if fallback
    concat yield if block_given?
  end
end