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.
This commit is contained in:
@@ -1,13 +1,3 @@
|
||||
<span class="comment-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? %>
|
||||
<span class="icon-deleted user-deleted"></span>
|
||||
<% elsif comment.user.organization? %>
|
||||
<%= special_avatar("avatar_collective.png", class: "avatar") %>
|
||||
<% else %>
|
||||
<%= render Shared::AvatarComponent.new(comment.user, size: 32) %>
|
||||
<% end %>
|
||||
<%= avatar %>
|
||||
</span>
|
||||
|
||||
@@ -7,6 +7,20 @@ class Comments::AvatarComponent < ApplicationComponent
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user