oembed_serializer.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. short_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. attributes = {
  31. src: embed_short_account_status_url(object.account, object),
  32. class: 'mastodon-embed',
  33. style: 'max-width: 100%; border: none;',
  34. width: width,
  35. height: height,
  36. }
  37. content_tag :iframe, nil, attributes
  38. end
  39. def width
  40. instance_options[:width]
  41. end
  42. def height
  43. instance_options[:height]
  44. end
  45. end