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.
-
#header_tags ⇒ Object
Tags to be used within the header of an article to describe the subject.
- #image_url(size: nil, transform: nil, fallback: true) ⇒ Object
- #preview_image_url(size: nil, transform: nil) ⇒ Object
-
#published_at ⇒ Object
Date the post was published.
-
#to_backend_card ⇒ Hash
The instance as a card.
-
#to_json_ld ⇒ Hash
JSON-LD representing the instance.
Methods inherited from BaseDecorator
#edit_backend_url, #render_active_block_list
Class Method Details
.collection_decorator_class ⇒ Object
Enables pagination
32 33 34 |
# File 'app/decorators/integral/post_decorator.rb', line 32 def self.collection_decorator_class PaginatingDecorator end |
Instance Method Details
#activity_url(activity_id) ⇒ String
Returns URL to backend activity.
108 109 110 111 112 113 114 |
# File 'app/decorators/integral/post_decorator.rb', line 108 def activity_url(activity_id) if Integral.blog_enabled? engine_url_helpers.activity_backend_post_url(object.id, activity_id) else '' end end |
#avatar ⇒ String
Returns avatar image.
65 66 67 |
# File 'app/decorators/integral/post_decorator.rb', line 65 def avatar h.image_tag user.avatar_url, class: 'user-avatar' if user.present? end |
#backend_url ⇒ String
Returns URL to backend post page.
99 100 101 102 103 104 105 |
# File 'app/decorators/integral/post_decorator.rb', line 99 def backend_url if Integral.blog_enabled? engine_url_helpers.backend_post_url(object.id) else '' end end |
#header_tags ⇒ Object
Tags to be used within the header of an article to describe the subject
70 71 72 73 74 75 76 77 78 79 |
# File 'app/decorators/integral/post_decorator.rb', line 70 def return I18n.t('integral.posts.show.subtitle') if object.(object.tag_context).empty? = '' object.(object.tag_context).each_with_index do |tag, i| += tag.name += ' | ' unless i == object.(object.tag_context).size - 1 end end |
#image_url(size: nil, transform: nil, fallback: true) ⇒ Object
87 88 89 |
# File 'app/decorators/integral/post_decorator.rb', line 87 def image_url(size: nil, transform: nil, fallback: true) image_variant_url(image, size: size, transform: transform, fallback: fallback) end |
#preview_image_url(size: nil, transform: nil) ⇒ Object
81 82 83 84 85 |
# File 'app/decorators/integral/post_decorator.rb', line 81 def preview_image_url(size: nil, transform: nil) return image_url(size: size, transform: transform) if preview_image.nil? image_variant_url(preview_image, size: size, transform: transform) end |
#published_at ⇒ Object
Date the post was published
92 93 94 95 96 |
# File 'app/decorators/integral/post_decorator.rb', line 92 def published_at return I18n.l(object.published_at, format: :blog) if object.published? 'Not yet published' end |
#to_backend_card ⇒ Hash
Returns the instance as a card.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/decorators/integral/post_decorator.rb', line 8 def to_backend_card image_url = object.image&.attached? ? app_url_helpers.url_for(image.) : nil attributes = [{ key: I18n.t('integral.records.attributes.status'), value: I18n.t("integral.records.status.#{status}") }] if Integral.multilingual_frontend? attributes += [{ key: I18n.t('integral.records.attributes.locale'), value: I18n.t("integral.language.#{locale}") }] end attributes += [ { key: I18n.t('integral.records.attributes.slug'), value: slug }, { key: I18n.t('integral.records.attributes.author'), value: .name }, { key: I18n.t('integral.records.attributes.views'), value: view_count }, { key: I18n.t('integral.records.attributes.tag_list'), value: .join(', ') }, { key: I18n.t('integral.records.attributes.updated_at'), value: I18n.l(updated_at) }, { key: I18n.t('integral.records.attributes.created_at'), value: I18n.l(created_at) } ] { image: image_url, description: title, url: backend_url, attributes: attributes } end |
#to_json_ld ⇒ Hash
Returns JSON-LD representing the instance.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/decorators/integral/post_decorator.rb', line 37 def to_json_ld { "@type": 'blogPosting', "mainEntityOfPage": object.frontend_url, "headline": title, "description": description, "datePublished": object.published_at, "dateModified": object.updated_at, "author": { "@type": 'Person', "name": object.&.name }, "image": [ preview_image_url(size: :large), image_url(size: :large) ], "publisher": { "@type": 'Organization', "name": Integral::Settings.website_title, "logo": { "@type": 'ImageObject', "url": h.image_url('logo.png') } } } end |