Class: Pageflow::PublishedEntry

Inherits:
EntryAtRevision show all
Extended by:
ActiveModel::Naming
Defined in:
app/models/pageflow/published_entry.rb

Overview

A merged view of an entry and its published revision.

Instance Attribute Summary collapse

Attributes inherited from EntryAtRevision

#entry, #revision

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EntryAtRevision

#emphasize_chapter_beginning, #emphasize_new_pages, #home_button, #manual_start, #overview_button, #resolve_widgets, #theme, wrap_all_drafts

Constructor Details

#initialize(entry, revision = nil, theme: nil) ⇒ PublishedEntry



14
15
16
17
# File 'app/models/pageflow/published_entry.rb', line 14

def initialize(entry, revision = nil, theme: nil)
  super(entry, revision || entry.published_revision, theme:)
  @custom_revision = revision
end

Instance Attribute Details

#share_targetObject

Returns the value of attribute share_target.



6
7
8
# File 'app/models/pageflow/published_entry.rb', line 6

def share_target
  @share_target
end

Class Method Details

.find(id, scope = Entry) ⇒ Object



66
67
68
# File 'app/models/pageflow/published_entry.rb', line 66

def self.find(id, scope = Entry)
  PublishedEntry.new(scope.published.find(id))
end


70
71
72
73
74
75
76
77
# File 'app/models/pageflow/published_entry.rb', line 70

def self.find_by_permalink(slug:, scope:, directory: nil)
  wrap(
    scope.published.includes(permalink: :directory).where(
      pageflow_permalink_directories: {path: directory || ''},
      pageflow_permalinks: {slug:}
    ).first
  )
end


79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/pageflow/published_entry.rb', line 79

def self.find_by_permalink_redirect(site:, slug:, directory: nil)
  wrap(
    PermalinkRedirect.joins(:entry, :directory).merge(Entry.published).where(
      slug:,
      pageflow_permalink_directories: {
        path: directory || '',
        site:
      }
    ).first&.entry
  )
end

.wrap_all(entries) ⇒ Object



91
92
93
94
# File 'app/models/pageflow/published_entry.rb', line 91

def self.wrap_all(entries)
  entries = entries.includes(:published_revision) unless entries.loaded?
  entries.map { |entry| new(entry) }
end

Instance Method Details

#cache_keyObject



96
97
98
99
100
101
102
103
# File 'app/models/pageflow/published_entry.rb', line 96

def cache_key
  [
    self.class.model_name.cache_key,
    entry.cache_key,
    revision.cache_key,
    site.cache_key
  ].compact.join('-')
end

#cache_versionObject



105
106
107
108
109
110
111
# File 'app/models/pageflow/published_entry.rb', line 105

def cache_version
  [
    entry.cache_version,
    revision.cache_version,
    site.cache_version
  ].compact.join('-').presence
end

#cutoff_mode_enabled_for?(request) ⇒ Boolean



37
38
39
# File 'app/models/pageflow/published_entry.rb', line 37

def cutoff_mode_enabled_for?(request)
  Pageflow.config.cutoff_modes.enabled_for?(self, request)
end

#page_thumbnail_file(page) ⇒ Object



59
60
61
62
63
64
# File 'app/models/pageflow/published_entry.rb', line 59

def page_thumbnail_file(page)
  return unless page.present?

  ThumbnailFileResolver.new(self, page.page_type.thumbnail_candidates, page.configuration)
                       .find_thumbnail
end

#published_revision?Boolean



113
114
115
# File 'app/models/pageflow/published_entry.rb', line 113

def published_revision?
  !custom_revision?
end

#stylesheet_cache_keyObject



45
46
47
# File 'app/models/pageflow/published_entry.rb', line 45

def stylesheet_cache_key
  revision.cache_key_with_version
end

#stylesheet_modelObject



41
42
43
# File 'app/models/pageflow/published_entry.rb', line 41

def stylesheet_model
  custom_revision? ? revision : entry
end

#thumbnail_fileObject



53
54
55
56
57
# File 'app/models/pageflow/published_entry.rb', line 53

def thumbnail_file
  share_image_file ||
    page_thumbnail_file(pages.first) ||
    PositionedFile.null
end

#thumbnail_urlObject



49
50
51
# File 'app/models/pageflow/published_entry.rb', line 49

def thumbnail_url(*)
  thumbnail_file.thumbnail_url(*)
end

#titleObject



19
20
21
# File 'app/models/pageflow/published_entry.rb', line 19

def title
  revision.title.presence || entry.title
end

#translations(scope = -> { self }, include_noindex: false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/pageflow/published_entry.rb', line 23

def translations(scope = -> { self }, include_noindex: false)
  return [] unless entry.translation_group

  if published_revision?
    self.class.wrap_all(
      published_translation_entries(include_noindex:).instance_exec(&scope)
    )
  else
    self.class.wrap_all_drafts(
      entry.translation_group.entries.instance_exec(&scope)
    )
  end
end