From 4e7493c75c416dd858132b0f5da8bdaa225514b4 Mon Sep 17 00:00:00 2001 From: Sergio Arbeo Date: Mon, 26 Oct 2015 01:43:18 +0100 Subject: [PATCH] Refactor comment body Refactor the body of the comment to use a couple of helpers instead of a long list of `if`s in the html. --- app/helpers/comments_helper.rb | 19 +++++++++++++++++++ app/views/comments/_comment.html.erb | 19 ++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 67c347ced..0f8eca926 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -17,4 +17,23 @@ module CommentsHelper comments.select{|c| c.parent_id == parent.id} end + def user_level_class(comment) + if comment.as_administrator? + "is-admin" + elsif comment.as_moderator? + "is-moderator" + elsif comment.user.official? + "level-#{comment.user.official_level}" + else + "" # Default no special user class + end + end + + def comment_author_class(comment, author_id) + if comment.user_id == author_id + "is-author" + else + "" # Default not author class + end + end end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index e2ce326aa..c353fb499 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -62,19 +62,12 @@  •  - <% if comment.as_administrator? %> -
<%= simple_format text_with_links comment.body %>
- <% elsif comment.as_moderator? %> -
<%= simple_format text_with_links comment.body %>
- <% elsif comment.user.official? && comment.user_id == @commentable.author_id %> -
<%= simple_format text_with_links comment.body %>
- <% elsif comment.user.official? %> -
<%= simple_format text_with_links comment.body %>
- <% elsif comment.user_id == @commentable.author_id %> -
<%= simple_format text_with_links comment.body %>
- <% else %> -
<%= simple_format text_with_links comment.body %>
- <% end %> +
+ <%= text_with_links comment.body %> +
+ <%= render 'comments/votes', comment: comment %>