闭社主体 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.

56 lines
1001 B

  1. # frozen_string_literal: true
  2. class OEmbedSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. include ActionView::Helpers::TagHelper
  5. attributes :type, :version, :title, :author_name,
  6. :author_url, :provider_name, :provider_url,
  7. :cache_age, :html, :width, :height
  8. def type
  9. 'rich'
  10. end
  11. def version
  12. '1.0'
  13. end
  14. def author_name
  15. object.account.display_name.presence || object.account.username
  16. end
  17. def author_url
  18. account_url(object.account)
  19. end
  20. def provider_name
  21. Rails.configuration.x.local_domain
  22. end
  23. def provider_url
  24. root_url
  25. end
  26. def cache_age
  27. 86_400
  28. end
  29. def html
  30. tag :iframe,
  31. src: embed_account_stream_entry_url(object.account, object),
  32. style: 'width: 100%; overflow: hidden',
  33. frameborder: '0',
  34. scrolling: 'no',
  35. width: width,
  36. height: height
  37. end
  38. def width
  39. instance_options[:width]
  40. end
  41. def height
  42. instance_options[:height]
  43. end
  44. end