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
-
#cache_key ⇒ Object
This cache key is used only for caching the content.
- #can_destroy? ⇒ Boolean
- #can_moderate? ⇒ Boolean
- #can_reply? ⇒ Boolean
- #can_update? ⇒ Boolean
- #destroy_path ⇒ Object
- #edit_path ⇒ Object
-
#initialize(post, policy, topic_view: nil) ⇒ 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) ⇒ PostView
Returns a new instance of PostView.
20 21 22 23 24 |
# File 'app/view_models/thredded/post_view.rb', line 20 def initialize(post, policy, topic_view: nil) @post = post @policy = policy @topic_view = topic_view end |
Instance Method Details
#cache_key ⇒ Object
This cache key is used only for caching the content.
71 72 73 |
# File 'app/view_models/thredded/post_view.rb', line 71 def cache_key @post.cache_key end |
#can_destroy? ⇒ Boolean
34 35 36 |
# File 'app/view_models/thredded/post_view.rb', line 34 def can_destroy? @can_destroy ||= @policy.destroy? end |
#can_moderate? ⇒ Boolean
38 39 40 |
# File 'app/view_models/thredded/post_view.rb', line 38 def can_moderate? @can_moderate ||= @policy.moderate? end |
#can_reply? ⇒ Boolean
26 27 28 |
# File 'app/view_models/thredded/post_view.rb', line 26 def can_reply? @can_reply ||= @policy.create? end |
#can_update? ⇒ Boolean
30 31 32 |
# File 'app/view_models/thredded/post_view.rb', line 30 def can_update? @can_update ||= @policy.update? end |
#destroy_path ⇒ Object
62 63 64 |
# File 'app/view_models/thredded/post_view.rb', line 62 def destroy_path Thredded::UrlsHelper.delete_post_path(@post) end |
#edit_path ⇒ Object
54 55 56 |
# File 'app/view_models/thredded/post_view.rb', line 54 def edit_path Thredded::UrlsHelper.edit_post_path(@post) end |
#mark_unread_path ⇒ Object
58 59 60 |
# File 'app/view_models/thredded/post_view.rb', line 58 def mark_unread_path Thredded::UrlsHelper.mark_unread_path(@post) end |
#permalink_path ⇒ Object
66 67 68 |
# File 'app/view_models/thredded/post_view.rb', line 66 def permalink_path Thredded::UrlsHelper.permalink_path(@post) end |
#quote_path ⇒ Object
50 51 52 |
# File 'app/view_models/thredded/post_view.rb', line 50 def quote_path Thredded::UrlsHelper.quote_post_path(@post) end |
#quote_url_params ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/view_models/thredded/post_view.rb', line 42 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)
79 80 81 82 83 84 85 86 87 |
# File 'app/view_models/thredded/post_view.rb', line 79 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 |