Class: Integral::PostDecorator
- Inherits:
-
Draper::Decorator
- Object
- Draper::Decorator
- 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.
-
#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.
83 84 85 86 87 88 89 |
# File 'app/decorators/integral/post_decorator.rb', line 83 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 |
#backend_url ⇒ String
Returns URL to backend post page.
74 75 76 77 78 79 80 |
# File 'app/decorators/integral/post_decorator.rb', line 74 def backend_url if Integral.blog_enabled? Integral::Engine.routes.url_helpers.edit_backend_post_url(object.id) else '' end end |
#body ⇒ String
Returns formatted body.
92 93 94 |
# File 'app/decorators/integral/post_decorator.rb', line 92 def body object.body&.html_safe end |
#header_tags ⇒ Object
Tags to be used within the header of an article to describe the subject
40 41 42 43 44 45 46 47 48 49 |
# File 'app/decorators/integral/post_decorator.rb', line 40 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
60 61 62 63 64 65 |
# File 'app/decorators/integral/post_decorator.rb', line 60 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
52 53 54 55 56 57 |
# File 'app/decorators/integral/post_decorator.rb', line 52 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
68 69 70 71 |
# File 'app/decorators/integral/post_decorator.rb', line 68 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 |