Class: Integral::PostDecorator
- Inherits:
-
Draper::Decorator
- Object
- Draper::Decorator
- Integral::PostDecorator
- Defined in:
- app/decorators/integral/post_decorator.rb
Overview
Page view-level logic
Instance Method Summary collapse
-
#activity_url(activity_id) ⇒ String
URL to backend activity.
-
#body ⇒ String
Formatted body.
-
#header_tags ⇒ Object
Tags to be used within the header of an article to describe the subject.
-
#image(size = :small, fallback = true) ⇒ Object
Image for the post if present.
-
#preview_image(size = :small) ⇒ Object
Preview image for the post if present.
-
#published_at ⇒ Object
Date the post was published.
-
#url ⇒ String
URL to backend post page.
Instance Method Details
#activity_url(activity_id) ⇒ String
Returns URL to backend activity.
50 51 52 53 54 55 56 |
# File 'app/decorators/integral/post_decorator.rb', line 50 def activity_url(activity_id) if Integral.blog_enabled? Integral::Engine.routes.url_helpers.activity_backend_post_url(object.id, activity_id) else '' end end |
#body ⇒ String
Returns formatted body.
59 60 61 |
# File 'app/decorators/integral/post_decorator.rb', line 59 def body object.body&.html_safe end |
#header_tags ⇒ Object
Tags to be used within the header of an article to describe the subject
7 8 9 10 11 12 13 14 15 16 |
# File 'app/decorators/integral/post_decorator.rb', line 7 def return I18n.t('integral.posts.show.subtitle') if object.('published').empty? = '' object.('published').each_with_index do |tag, i| += tag.name += ' | ' unless i == object.('published').size - 1 end end |
#image(size = :small, fallback = true) ⇒ Object
Image for the post if present. Otherwise returns default image
27 28 29 30 31 32 |
# File 'app/decorators/integral/post_decorator.rb', line 27 def image(size = :small, fallback = true) image = object&.image&.url(size) return image if image.present? h.image_url('integral/defaults/no_image_available.jpg') if fallback end |
#preview_image(size = :small) ⇒ Object
Preview image for the post if present. Otherwise returns featured image
19 20 21 22 23 24 |
# File 'app/decorators/integral/post_decorator.rb', line 19 def preview_image(size = :small) preview_image = object&.preview_image&.url(size) return preview_image if preview_image.present? image(size, false) end |
#published_at ⇒ Object
Date the post was published
35 36 37 38 |
# File 'app/decorators/integral/post_decorator.rb', line 35 def published_at return I18n.l(object.published_at, format: :blog) if object.published? 'Not yet published' end |
#url ⇒ String
Returns URL to backend post page.
41 42 43 44 45 46 47 |
# File 'app/decorators/integral/post_decorator.rb', line 41 def url if Integral.blog_enabled? Integral::Engine.routes.url_helpers.edit_backend_post_url(object.id) else '' end end |