Files
grecia/app/components/comments/avatar_component.rb
Javi Martín ccaa873e2a Use Ruby instead of ERB to render comment avatars
Reading conditions in Ruby is much easier than reading them in ERB and,
since the block only had only HTML tag (the <span> tag for deleted
users) but was using Ruby in all other four cases, we're moving it to a
Ruby file.
2024-04-11 18:48:33 +02:00

28 lines
808 B
Ruby

class Comments::AvatarComponent < ApplicationComponent
attr_reader :comment
def initialize(comment)
@comment = comment
end
private
def avatar
if comment.as_administrator?
special_avatar("avatar_admin.png", class: "admin-avatar")
elsif comment.as_moderator?
special_avatar("avatar_moderator.png", class: "moderator-avatar")
elsif comment.user.hidden? || comment.user.erased?
tag.span(class: "icon-deleted user-deleted")
elsif comment.user.organization?
special_avatar("avatar_collective.png", class: "avatar")
else
render Shared::AvatarComponent.new(comment.user, size: 32)
end
end
def special_avatar(image_name, options = {})
image_tag(image_name, { size: 32, alt: "" }.merge(options))
end
end