about summary refs log tree commit diff
path: root/app/serializers/oembed_serializer.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-07-08 14:51:05 +0200
committerGitHub <noreply@github.com>2017-07-08 14:51:05 +0200
commit864e3f8d9ca652e10a28bddbb0d0df629d2849d4 (patch)
tree3fb2f9c97fca49cc467622ab532252f8044146f6 /app/serializers/oembed_serializer.rb
parent102466ac5842b20f32a9c5e2fa3f35414c34574b (diff)
Replace OEmbed and initial state Rabl templates with serializers (#4110)
* Replace OEmbed Rabl template with serializer

* Replace initial state rabl with serializer
Diffstat (limited to 'app/serializers/oembed_serializer.rb')
-rw-r--r--app/serializers/oembed_serializer.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/serializers/oembed_serializer.rb b/app/serializers/oembed_serializer.rb
new file mode 100644
index 000000000..78376d253
--- /dev/null
+++ b/app/serializers/oembed_serializer.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+class OEmbedSerializer < ActiveModel::Serializer
+  include RoutingHelper
+  include ActionView::Helpers::TagHelper
+
+  attributes :type, :version, :title, :author_name,
+             :author_url, :provider_name, :provider_url,
+             :cache_age, :html, :width, :height
+
+  def type
+    'rich'
+  end
+
+  def version
+    '1.0'
+  end
+
+  def author_name
+    object.account.display_name.presence || object.account.username
+  end
+
+  def author_url
+    account_url(object.account)
+  end
+
+  def provider_name
+    Rails.configuration.x.local_domain
+  end
+
+  def provider_url
+    root_url
+  end
+
+  def cache_age
+    86_400
+  end
+
+  def html
+    tag :iframe,
+        src: embed_account_stream_entry_url(object.account, object),
+        style: 'width: 100%; overflow: hidden',
+        frameborder: '0',
+        scrolling: 'no',
+        width: width,
+        height: height
+  end
+
+  def width
+    instance_options[:width]
+  end
+
+  def height
+    instance_options[:height]
+  end
+end