Module: Spree::Admin::AvatarsHelper
- Includes:
- ImagesHelper
- Defined in:
- app/helpers/spree/admin/avatars_helper.rb
Constant Summary collapse
- AVATAR_GRADIENTS =
[ 'bg-gradient-to-br from-indigo-500 to-purple-600', 'bg-gradient-to-br from-pink-400 to-rose-500', 'bg-gradient-to-br from-blue-400 to-cyan-400', 'bg-gradient-to-br from-emerald-400 to-teal-400', 'bg-gradient-to-br from-rose-400 to-yellow-300', 'bg-gradient-to-br from-teal-200 to-pink-200', 'bg-gradient-to-br from-rose-300 to-pink-200', 'bg-gradient-to-br from-orange-200 to-orange-400', 'bg-gradient-to-br from-violet-500 to-fuchsia-500', 'bg-gradient-to-br from-amber-400 to-orange-500', ].freeze
Instance Method Summary collapse
- #avatar_gradient_class(identifier) ⇒ Object
-
#render_avatar(user, options = {}) ⇒ String
render an avatar for a user if user doesn’t have an avatar, the user’s initials will be displayed on a rounded-lg background.
Instance Method Details
#avatar_gradient_class(identifier) ⇒ Object
19 20 21 22 |
# File 'app/helpers/spree/admin/avatars_helper.rb', line 19 def avatar_gradient_class(identifier) index = Digest::MD5.hexdigest(identifier.to_s)[0..7].to_i(16) % AVATAR_GRADIENTS.length AVATAR_GRADIENTS[index] end |
#render_avatar(user, options = {}) ⇒ String
render an avatar for a user if user doesn’t have an avatar, the user’s initials will be displayed on a rounded-lg background
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/spree/admin/avatars_helper.rb', line 32 def render_avatar(user, = {}) return unless user.present? [:width] ||= 128 [:height] ||= 128 [:class] ||= 'avatar rounded-lg flex items-center justify-center text-white text-lg' if user.respond_to?(:avatar) && user.avatar.attached? && user.avatar.variable? spree_image_tag( user.avatar, width: [:width], height: [:height], class: [:class], style: "width: #{[:width]}px; height: #{[:height]}px;" ) else gradient = avatar_gradient_class(user.email) content_tag :div, user.name&.initials, class: "#{gradient} #{[:class]}", style: "width: #{[:width]}px; height: #{[:height]}px;" end end |