Class: Integral::PostDecorator
- Inherits:
-
BaseDecorator
- Object
- Draper::Decorator
- BaseDecorator
- Integral::PostDecorator
- Defined in:
- app/decorators/integral/post_decorator.rb
Overview
Page view-level logic
Class Method Summary collapse
-
.collection_decorator_class ⇒ Object
Enables pagination.
Instance Method Summary collapse
-
#activity_url(activity_id) ⇒ String
URL to backend activity.
-
#avatar ⇒ String
Avatar image.
-
#backend_url ⇒ String
URL to backend post page.
-
#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.
-
#to_json_ld ⇒ Hash
JSON-LD representing the instance.
Class Method Details
.collection_decorator_class ⇒ Object
Enables pagination
7 8 9 |
# File 'app/decorators/integral/post_decorator.rb', line 7 def self.collection_decorator_class PaginatingDecorator end |
Instance Method Details
#activity_url(activity_id) ⇒ String
Returns URL to backend activity.
90 91 92 93 94 95 96 |
# File 'app/decorators/integral/post_decorator.rb', line 90 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 |
#avatar ⇒ String
Returns avatar image.
40 41 42 43 |
# File 'app/decorators/integral/post_decorator.rb', line 40 def avatar avatar_url = user&.avatar&.url(:thumbnail) h.image_tag avatar_url, class: 'user-avatar' unless avatar_url.nil? end |
#backend_url ⇒ String
Returns URL to backend post page.
81 82 83 84 85 86 87 |
# File 'app/decorators/integral/post_decorator.rb', line 81 def backend_url if Integral.blog_enabled? Integral::Engine.routes.url_helpers.backend_post_url(object.id) else '' end end |
#body ⇒ String
Returns formatted body.
99 100 101 |
# File 'app/decorators/integral/post_decorator.rb', line 99 def body object.body&.html_safe end |
#header_tags ⇒ Object
Tags to be used within the header of an article to describe the subject
46 47 48 49 50 51 52 53 54 55 |
# File 'app/decorators/integral/post_decorator.rb', line 46 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
66 67 68 69 70 71 |
# File 'app/decorators/integral/post_decorator.rb', line 66 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
58 59 60 61 62 63 |
# File 'app/decorators/integral/post_decorator.rb', line 58 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
74 75 76 77 78 |
# File 'app/decorators/integral/post_decorator.rb', line 74 def published_at return I18n.l(object.published_at, format: :blog) if object.published? 'Not yet published' end |
#to_json_ld ⇒ Hash
Returns JSON-LD representing the instance.
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 |
# File 'app/decorators/integral/post_decorator.rb', line 12 def to_json_ld { "@type": 'blogPosting', "mainEntityOfPage": Integral::Engine.routes.url_helpers.post_url(object), "headline": title, "description": description, "datePublished": object.published_at, "dateModified": object.updated_at, "author": { "@type": 'Person', "name": object.&.name }, "image": [ preview_image(:large), image(:large) ], "publisher": { "@type": 'Organization', "name": Integral::Settings.website_title, "logo": { "@type": 'ImageObject', "url": h.image_url('logo.png') } } } end |