Class: Thredded::PostView
- Inherits:
-
Object
- Object
- Thredded::PostView
- Defined in:
- app/view_models/thredded/post_view.rb
Overview
A view model for PostCommon.
Constant Summary collapse
- POST_IS_READ =
:read
- POST_IS_UNREAD =
:unread
Instance Method Summary collapse
- #can_destroy? ⇒ Boolean
- #can_moderate? ⇒ Boolean
- #can_reply? ⇒ Boolean
- #can_update? ⇒ Boolean
- #destroy_path ⇒ Object
- #edit_path ⇒ Object
- #first_in_page? ⇒ Boolean
- #first_unread_in_page? ⇒ Boolean
-
#initialize(post, policy, topic_view: nil, first_in_page: false, first_unread_in_page: false) ⇒ PostView
constructor
A new instance of PostView.
- #mark_unread_path ⇒ Object
- #permalink_path ⇒ Object
- #quote_path ⇒ Object
- #quote_url_params ⇒ Object
-
#read_state ⇒ Object
returns nil if read state is not appropriate to the view (i.e. viewing posts outside a topic).
Constructor Details
#initialize(post, policy, topic_view: nil, first_in_page: false, first_unread_in_page: false) ⇒ PostView
Returns a new instance of PostView.
25 26 27 28 29 30 31 |
# File 'app/view_models/thredded/post_view.rb', line 25 def initialize(post, policy, topic_view: nil, first_in_page: false, first_unread_in_page: false) @post = post @policy = policy @topic_view = topic_view @first_unread_in_page = first_unread_in_page @first_in_page = first_in_page end |
Instance Method Details
#can_destroy? ⇒ Boolean
41 42 43 |
# File 'app/view_models/thredded/post_view.rb', line 41 def can_destroy? @can_destroy ||= @policy.destroy? end |
#can_moderate? ⇒ Boolean
45 46 47 |
# File 'app/view_models/thredded/post_view.rb', line 45 def can_moderate? @can_moderate ||= @policy.moderate? end |
#can_reply? ⇒ Boolean
33 34 35 |
# File 'app/view_models/thredded/post_view.rb', line 33 def can_reply? @can_reply ||= @policy.create? end |
#can_update? ⇒ Boolean
37 38 39 |
# File 'app/view_models/thredded/post_view.rb', line 37 def can_update? @can_update ||= @policy.update? end |
#destroy_path ⇒ Object
69 70 71 |
# File 'app/view_models/thredded/post_view.rb', line 69 def destroy_path Thredded::UrlsHelper.delete_post_path(@post) end |
#edit_path ⇒ Object
61 62 63 |
# File 'app/view_models/thredded/post_view.rb', line 61 def edit_path Thredded::UrlsHelper.edit_post_path(@post) end |
#first_in_page? ⇒ Boolean
95 96 97 |
# File 'app/view_models/thredded/post_view.rb', line 95 def first_in_page? @first_in_page end |
#first_unread_in_page? ⇒ Boolean
91 92 93 |
# File 'app/view_models/thredded/post_view.rb', line 91 def first_unread_in_page? @first_unread_in_page end |
#mark_unread_path ⇒ Object
65 66 67 |
# File 'app/view_models/thredded/post_view.rb', line 65 def mark_unread_path Thredded::UrlsHelper.mark_unread_path(@post) end |
#permalink_path ⇒ Object
73 74 75 |
# File 'app/view_models/thredded/post_view.rb', line 73 def permalink_path Thredded::UrlsHelper.permalink_path(@post) end |
#quote_path ⇒ Object
57 58 59 |
# File 'app/view_models/thredded/post_view.rb', line 57 def quote_path Thredded::UrlsHelper.quote_post_path(@post) end |
#quote_url_params ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/view_models/thredded/post_view.rb', line 49 def quote_url_params if @post.private_topic_post? { post: { quote_private_post_id: @post.id } } else { post: { quote_post_id: @post.id } } end.update(anchor: 'post_content') end |
#read_state ⇒ Object
returns nil if read state is not appropriate to the view (i.e. viewing posts outside a topic)
81 82 83 84 85 86 87 88 89 |
# File 'app/view_models/thredded/post_view.rb', line 81 def read_state if @topic_view.nil? || @policy.anonymous? nil elsif @topic_view.post_read?(@post) POST_IS_READ else POST_IS_UNREAD end end |