Class: Integral::PostDecorator

Inherits:
BaseDecorator show all
Defined in:
app/decorators/integral/post_decorator.rb

Overview

Page view-level logic

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDecorator

#edit_backend_url, #render_active_block_list

Class Method Details

.collection_decorator_classObject

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.

Returns:

  • (String)

    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

#avatarString

Returns avatar image.

Returns:

  • (String)

    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_urlString

Returns URL to backend post page.

Returns:

  • (String)

    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_tagsObject

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 header_tags
  return I18n.t('integral.posts.show.subtitle') if object.tags_on(object.tag_context).empty?

  header_tags = ''
  object.tags_on(object.tag_context).each_with_index do |tag, i|
    header_tags += tag.name
    header_tags += ' | ' unless i == object.tags_on(object.tag_context).size - 1
  end
  header_tags
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_atObject

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_cardHash

Returns the instance as a card.

Returns:

  • (Hash)

    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.attachment) : 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: author.name },
    { key: I18n.t('integral.records.attributes.views'), value: view_count },
    { key: I18n.t('integral.records.attributes.tag_list'), value: tags.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_ldHash

Returns JSON-LD representing the instance.

Returns:

  • (Hash)

    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.author&.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