Welcome to mirror list, hosted at ThFree Co, Russian Federation.

o_embed_presenter.rb « presenters « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e8961460b19fc213f0dd5c1330a7b56c3c85dc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

class OEmbedPresenter
  include PostsHelper

  def initialize(post, opts = {})
    @post = post
    @opts = opts
  end

  def to_json(opts={})
    as_json(opts).to_json
  end

  def as_json(opts={})
    {
      :provider_name => "Diaspora",
      :provider_url => AppConfig.pod_uri.to_s,
      :type => 'rich',
      :version => '1.0',
      :title => post_title,
      :author_name => post_author,
      :author_url => post_author_url,
      :width => @opts.fetch(:maxwidth, 516),
      :height => @opts.fetch(:maxheight, 320),
      :html => iframe_html
    }
  end

  def self.id_from_url(url)
    URI.parse(url).path.gsub(%r{\/posts\/|\/p\/}, '')
  end

  def post_title
    post_page_title(@post)
  end

  def post_author
    @post.author_name
  end

  def post_author_url
    AppConfig.url_to(Rails.application.routes.url_helpers.person_path(@post.author))
  end

  def iframe_html
    post_iframe_url(@post.id, :height => @opts[:maxheight], :width => @opts[:maxwidth])
  end
end