Extract method to render special avatars in comments

This commit is contained in:
Javi Martín
2024-04-11 17:15:41 +02:00
parent 67b1518858
commit c655edddde
2 changed files with 9 additions and 3 deletions

View File

@@ -1,12 +1,12 @@
<span class="comment-avatar">
<% if comment.as_administrator? %>
<%= image_tag("avatar_admin.png", size: 32, class: "admin-avatar", alt: "") %>
<%= special_avatar("avatar_admin.png", class: "admin-avatar") %>
<% elsif comment.as_moderator? %>
<%= image_tag("avatar_moderator.png", size: 32, class: "moderator-avatar", alt: "") %>
<%= special_avatar("avatar_moderator.png", class: "moderator-avatar") %>
<% elsif comment.user.hidden? || comment.user.erased? %>
<span class="icon-deleted user-deleted"></span>
<% elsif comment.user.organization? %>
<%= image_tag("avatar_collective.png", size: 32, class: "avatar", alt: "") %>
<%= special_avatar("avatar_collective.png", class: "avatar") %>
<% else %>
<%= render Shared::AvatarComponent.new(comment.user, size: 32) %>
<% end %>

View File

@@ -4,4 +4,10 @@ class Comments::AvatarComponent < ApplicationComponent
def initialize(comment)
@comment = comment
end
private
def special_avatar(image_name, options = {})
image_tag(image_name, { size: 32, alt: "" }.merge(options))
end
end