Class: Spree::Post

Inherits:
Object
  • Object
show all
Extended by:
FriendlyId
Includes:
PgSearch::Model, Linkable, Metafields, SingleStoreResource
Defined in:
app/models/spree/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.to_tom_select_jsonObject



102
103
104
105
106
107
108
109
# File 'app/models/spree/post.rb', line 102

def self.to_tom_select_json
  pluck(:id, :title).map do |id, title|
    {
      id: id,
      name: title
    }
  end.as_json
end

Instance Method Details

#descriptionObject



93
94
95
# File 'app/models/spree/post.rb', line 93

def description
  excerpt.to_plain_text.presence || content.to_plain_text
end

#page_builder_urlObject



79
80
81
82
83
# File 'app/models/spree/post.rb', line 79

def page_builder_url
  return unless Spree::Core::Engine.routes.url_helpers.respond_to?(:post_path)

  Spree::Core::Engine.routes.url_helpers.post_path(self)
end

#publish(date = nil) ⇒ Object



85
86
87
# File 'app/models/spree/post.rb', line 85

def publish(date = nil)
  update(published_at: date || Time.current)
end

#published?Boolean



75
76
77
# File 'app/models/spree/post.rb', line 75

def published?
  published_at.present?
end

#shortened_descriptionObject



97
98
99
100
# File 'app/models/spree/post.rb', line 97

def shortened_description
  desc = excerpt.to_plain_text.presence || content.to_plain_text
  desc.length > 320 ? "#{desc[0...320]}..." : desc
end

#should_generate_new_friendly_id?Boolean



64
65
66
# File 'app/models/spree/post.rb', line 64

def should_generate_new_friendly_id?
  slug.blank? || (persisted? && title_changed?)
end

#slug_candidatesObject



68
69
70
71
72
73
# File 'app/models/spree/post.rb', line 68

def slug_candidates
  [
    :title,
    [:title, :id]
  ]
end

#unpublishObject



89
90
91
# File 'app/models/spree/post.rb', line 89

def unpublish
  update(published_at: nil)
end