views: factor out humanized_number helper.

* Render counts in the user profile tooltip the same way as tag counts.
* Render tag counts in the tags index page the same way as tag counts in
  the tags list.
This commit is contained in:
evazion
2021-02-18 19:16:41 -06:00
parent bcca0ca53a
commit 4ef30844f6
5 changed files with 11 additions and 14 deletions

View File

@@ -122,7 +122,13 @@ module ApplicationHelper
end
def humanized_number(number)
number_to_human number, units: { thousand: "k", million: "m" }, format: "%n%u"
if number >= 10_000
"#{number / 1_000}k"
elsif number >= 1_000
"%.1fk" % (number / 1_000.0)
else
number.to_s
end
end
def time_ago_in_words_tagged(time, compact: false)