Class: Integral::PostDecorator

Inherits:
Draper::Decorator
  • Object
show all
Defined in:
app/decorators/integral/post_decorator.rb

Overview

Page view-level logic

Instance Method Summary collapse

Instance Method Details

#activity_url(activity_id) ⇒ String

Returns URL to backend activity.

Returns:

  • (String)

    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

#bodyString

Returns formatted body.

Returns:

  • (String)

    formatted body



59
60
61
# File 'app/decorators/integral/post_decorator.rb', line 59

def body
  object.body&.html_safe
end

#header_tagsObject

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

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

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

#urlString

Returns URL to backend post page.

Returns:

  • (String)

    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