accounts_helper.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. module AccountsHelper
  3. def display_name(account, **options)
  4. str = account.display_name.presence || account.username
  5. if options[:custom_emojify]
  6. prerender_custom_emojis(h(str), account.emojis)
  7. else
  8. str
  9. end
  10. end
  11. def acct(account)
  12. if account.local?
  13. "@#{account.acct}@#{site_hostname}"
  14. else
  15. "@#{account.pretty_acct}"
  16. end
  17. end
  18. def account_formatted_stat(value)
  19. number_to_human(value, precision: 3, strip_insignificant_zeros: true)
  20. end
  21. def account_description(account)
  22. prepend_str = [
  23. [
  24. account_formatted_stat(account.statuses_count),
  25. I18n.t('accounts.posts', count: account.statuses_count),
  26. ].join(' '),
  27. [
  28. account_formatted_stat(account.following_count),
  29. I18n.t('accounts.following', count: account.following_count),
  30. ].join(' '),
  31. [
  32. account_formatted_stat(account.followers_count),
  33. I18n.t('accounts.followers', count: account.followers_count),
  34. ].join(' '),
  35. ].join(', ')
  36. [prepend_str, account.note].join(' · ')
  37. end
  38. end