From b8701e762609b4990c1608b5121c6ec60a716ee7 Mon Sep 17 00:00:00 2001
From: Georg Gadinger <nilsding@nilsding.org>
Date: Thu, 30 Mar 2017 19:17:25 +0200
Subject: [PATCH] Make user_screen_name helper use kwargs, add link_only arg

---
 app/helpers/application_helper.rb          | 6 +++---
 app/helpers/user_helper.rb                 | 8 ++++++--
 app/views/inbox/_entry.html.haml           | 2 +-
 app/views/shared/_answerbox.html.haml      | 2 +-
 app/views/shared/_comment_smiles.html.haml | 4 ++--
 app/views/shared/_question.html.haml       | 2 +-
 app/views/shared/_question_header.haml     | 4 ++--
 7 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1b02ae2b..dd1c7651 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -132,17 +132,17 @@ module ApplicationHelper
   end
 
   def question_title(question)
-    name = user_screen_name question.user, question.author_is_anonymous, false
+    name = user_screen_name question.user, anonymous: question.author_is_anonymous, url: false
     generate_title name, "asked", question.content
   end
 
   def answer_title(answer)
-    name = user_screen_name answer.user, false, false
+    name = user_screen_name answer.user, anonymous: false, url: false
     generate_title name, "answered", answer.question.content
   end
 
   def user_title(user, junction = nil)
-    name = user_screen_name user, false, false
+    name = user_screen_name user, anonymous: false, url: false
     generate_title name, junction, nil, !junction.nil?
   end
 
diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb
index cd68bf14..3abe244b 100644
--- a/app/helpers/user_helper.rb
+++ b/app/helpers/user_helper.rb
@@ -1,10 +1,14 @@
 module UserHelper
   # Decides what user name to show.
   # @return [String] The user name
-  def user_screen_name(user, anonymous=false, url=true)
+  def user_screen_name(user, anonymous: false, url: true, link_only: false)
     return APP_CONFIG['anonymous_name'] if user.nil? || anonymous
     name = user.display_name.blank? ? user.screen_name : user.display_name
-    return link_to(name, show_user_profile_path(user.screen_name), class: "#{"user--banned" if user.banned?}") if url
+    if url
+      link = show_user_profile_path(user.screen_name)
+      return link if link_only
+      return link_to(name, link, class: "#{"user--banned" if user.banned?}")
+    end
     name.strip
   end
 end
diff --git a/app/views/inbox/_entry.html.haml b/app/views/inbox/_entry.html.haml
index 93adc252..68ea268d 100644
--- a/app/views/inbox/_entry.html.haml
+++ b/app/views/inbox/_entry.html.haml
@@ -6,7 +6,7 @@
           %img.img-rounded.answerbox--img{src: gravatar_url(i.question.user)}
       .media-body
         %h6.text-muted.media-heading.answerbox--question-user
-          = raw t('views.inbox.entry.asked', user: user_screen_name(i.question.user, i.question.author_is_anonymous), time: time_tooltip(i.question))
+          = raw t('views.inbox.entry.asked', user: user_screen_name(i.question.user, anonymous: i.question.author_is_anonymous), time: time_tooltip(i.question))
           - unless i.question.author_is_anonymous
             - if i.question.answer_count > 0
               ·
diff --git a/app/views/shared/_answerbox.html.haml b/app/views/shared/_answerbox.html.haml
index a015e3f2..7439f1d9 100644
--- a/app/views/shared/_answerbox.html.haml
+++ b/app/views/shared/_answerbox.html.haml
@@ -23,7 +23,7 @@
                         %i.fa.fa-exclamation-triangle
                         = t 'views.actions.report'
           %h6.text-muted.media-heading.answerbox--question-user
-            = raw t('views.answerbox.asked', user: user_screen_name(a.question.user, a.question.author_is_anonymous), time: time_tooltip(a.question))
+            = raw t('views.answerbox.asked', user: user_screen_name(a.question.user, anonymous: a.question.author_is_anonymous), time: time_tooltip(a.question))
             - unless a.question.author_is_anonymous
               - if a.question.answer_count > 1
                 ·
diff --git a/app/views/shared/_comment_smiles.html.haml b/app/views/shared/_comment_smiles.html.haml
index 7eaee04d..f3b8aebb 100644
--- a/app/views/shared/_comment_smiles.html.haml
+++ b/app/views/shared/_comment_smiles.html.haml
@@ -14,5 +14,5 @@
             - comment.smiles.all.each do |smile|
               %li.user-list-entry.user-list-entry-smiles
                 %a{href: show_user_profile_path(smile.user.screen_name)}
-                  %img.img-rounded{src: gravatar_url(smile.user), alt: user_screen_name(smile.user, false, false)}
-                  %span= user_screen_name(smile.user, false, false)
+                  %img.img-rounded{src: gravatar_url(smile.user), alt: user_screen_name(smile.user, url: false)}
+                  %span= user_screen_name(smile.user, url: false)
diff --git a/app/views/shared/_question.html.haml b/app/views/shared/_question.html.haml
index 4e7717c3..1bb89fb9 100644
--- a/app/views/shared/_question.html.haml
+++ b/app/views/shared/_question.html.haml
@@ -4,7 +4,7 @@
     .media
       - if type == "discover"
         .pull-left
-          %a{href: show_user_profile_path(q.user.screen_name)}
+          %a{href: user_screen_name(q.user.screen_name, link_only: true)}
             %img.answerbox--img{src: q.user.profile_picture.url(:medium)}
       .media-body
         - if user_signed_in?
diff --git a/app/views/shared/_question_header.haml b/app/views/shared/_question_header.haml
index 5dcefad7..31e2d2ff 100644
--- a/app/views/shared/_question_header.haml
+++ b/app/views/shared/_question_header.haml
@@ -25,7 +25,7 @@
                           = t 'views.actions.report'
           %h6.text-muted.media-heading.answerbox--question-user
             - if hidden
-              = user_screen_name question.user, question.author_is_anonymous, false
+              = user_screen_name question.user, anonymous: question.author_is_anonymous, url: false
             - else
-              = raw t('views.answerbox.asked', user: user_screen_name(question.user, question.author_is_anonymous), time: time_tooltip(question))
+              = raw t('views.answerbox.asked', user: user_screen_name(question.user, anonymous: question.author_is_anonymous), time: time_tooltip(question))
           %p.answerbox--question-text= question.content