Class: PostPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/post_presenter.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (PostPresenter) initialize(post, current_user = nil)

A new instance of PostPresenter



4
5
6
7
# File 'app/presenters/post_presenter.rb', line 4

def initialize(post, current_user = nil)
  @post = post
  @current_user = current_user
end

Instance Attribute Details

- (Object) current_user

Returns the value of attribute current_user



2
3
4
# File 'app/presenters/post_presenter.rb', line 2

def current_user
  @current_user
end

- (Object) post

Returns the value of attribute post



2
3
4
# File 'app/presenters/post_presenter.rb', line 2

def post
  @post
end

Class Method Details

+ (Object) collection_json(collection, current_user)



9
10
11
# File 'app/presenters/post_presenter.rb', line 9

def self.collection_json(collection, current_user)
  collection.map {|post| PostPresenter.new(post, current_user)}
end

Instance Method Details

- (Object) as_json(options = {})



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
# File 'app/presenters/post_presenter.rb', line 13

def as_json(options={})
  {
      :id => @post.id,
      :guid => @post.guid,
      :text => @post.raw_message,
      :public => @post.public,
      :created_at => @post.created_at,
      :interacted_at => @post.interacted_at,
      :provider_display_name => @post.provider_display_name,
      :post_type => @post.post_type,
      :image_url => @post.image_url,
      :object_url => @post.object_url,
      :favorite => @post.favorite,
      :nsfw => @post.nsfw,
      :author => @post.author.as_api_response(:backbone),
      :o_embed_cache => @post.o_embed_cache.try(:as_api_response, :backbone),
      :mentioned_people => @post.mentioned_people.as_api_response(:backbone),
      :photos => @post.photos.map {|p| p.as_api_response(:backbone)},
      :frame_name => @post.frame_name || template_name,
      :root => root,
      :title => title,
      :next_post => next_post_path,
      :previous_post => previous_post_path,
      :address => @post.address,

      :interactions => {
          :likes => [user_like].compact,
          :reshares => [user_reshare].compact,
          :comments_count => @post.comments_count,
          :likes_count => @post.likes_count,
          :reshares_count => @post.reshares_count,
      }
  }
end

- (Object) next_post_path



48
49
50
# File 'app/presenters/post_presenter.rb', line 48

def next_post_path
  Rails.application.routes.url_helpers.next_post_path(@post)
end

- (Object) previous_post_path



52
53
54
# File 'app/presenters/post_presenter.rb', line 52

def previous_post_path
  Rails.application.routes.url_helpers.previous_post_path(@post)
end

- (Object) root



64
65
66
# File 'app/presenters/post_presenter.rb', line 64

def root
  PostPresenter.new(@post.absolute_root, current_user).as_json if @post.respond_to?(:absolute_root) && @post.absolute_root.present?
end

- (Object) template_name

kill me, lol, I should be client side



60
61
62
# File 'app/presenters/post_presenter.rb', line 60

def template_name #kill me, lol, I should be client side
  @template_name ||= TemplatePicker.new(@post).template_name
end

- (Object) title



56
57
58
# File 'app/presenters/post_presenter.rb', line 56

def title
  @post.text.present? ? @post.text(:plain_text => true) : I18n.translate('posts.presenter.title', :name => @post.author_name)
end

- (Object) user_like



68
69
70
# File 'app/presenters/post_presenter.rb', line 68

def user_like
  @post.like_for(@current_user).try(:as_api_response, :backbone)
end

- (Object) user_reshare



72
73
74
# File 'app/presenters/post_presenter.rb', line 72

def user_reshare
  @post.reshare_for(@current_user)
end