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.

58 lines
1.1 KiB

  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: 0',
  34. width: width,
  35. height: height,
  36. }
  37. content_tag(:iframe, nil, attributes) + content_tag(:script, nil, src: full_asset_url('embed.js'), async: true)
  38. end
  39. def width
  40. instance_options[:width]
  41. end
  42. def height
  43. instance_options[:height]
  44. end
  45. end