闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. module StreamEntriesHelper
  3. def display_name(account)
  4. account.display_name.presence || account.username
  5. end
  6. def stream_link_target
  7. embedded_view? ? '_blank' : nil
  8. end
  9. def acct(account)
  10. "@#{account.acct}#{embedded_view? && account.local? ? "@#{Rails.configuration.x.local_domain}" : ''}"
  11. end
  12. def style_classes(status, is_predecessor, is_successor, include_threads)
  13. classes = ['entry']
  14. classes << 'entry-predecessor' if is_predecessor
  15. classes << 'entry-reblog' if status.reblog?
  16. classes << 'entry-successor' if is_successor
  17. classes << 'entry-center' if include_threads
  18. classes.join(' ')
  19. end
  20. def microformats_classes(status, is_direct_parent, is_direct_child)
  21. classes = []
  22. classes << 'p-in-reply-to' if is_direct_parent
  23. classes << 'p-repost-of' if status.reblog? && is_direct_parent
  24. classes << 'p-comment' if is_direct_child
  25. classes.join(' ')
  26. end
  27. def microformats_h_class(status, is_predecessor, is_successor, include_threads)
  28. return 'h-cite' if is_predecessor || status.reblog || is_successor
  29. return 'h-entry' unless include_threads
  30. ''
  31. end
  32. def rtl?(text)
  33. return false if text.empty?
  34. matches = /[\p{Hebrew}|\p{Arabic}|\p{Syriac}|\p{Thaana}|\p{Nko}]+/m.match(text)
  35. return false unless matches
  36. rtl_size = matches.to_a.reduce(0) { |acc, elem| acc + elem.size }.to_f
  37. ltr_size = text.strip.size.to_f
  38. rtl_size / ltr_size > 0.3
  39. end
  40. private
  41. def embedded_view?
  42. params[:controller] == 'stream_entries' && params[:action] == 'embed'
  43. end
  44. end