Class: Spree::Post
- Inherits:
-
Object
- Object
- Spree::Post
- Extended by:
- FriendlyId
- Includes:
- PgSearch::Model, Metafields, SingleStoreResource
- Defined in:
- app/models/spree/post.rb
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
- #publish(date = nil) ⇒ Object
- #published? ⇒ Boolean
- #shortened_description ⇒ Object
- #should_generate_new_friendly_id? ⇒ Boolean
- #slug_candidates ⇒ Object
- #unpublish ⇒ Object
Class Method Details
.to_tom_select_json ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'app/models/spree/post.rb', line 97 def self.to_tom_select_json pluck(:id, :title).map do |id, title| { id: id, name: title } end.as_json end |
Instance Method Details
#description ⇒ Object
88 89 90 |
# File 'app/models/spree/post.rb', line 88 def description excerpt.to_plain_text.presence || content.to_plain_text end |
#publish(date = nil) ⇒ Object
80 81 82 |
# File 'app/models/spree/post.rb', line 80 def publish(date = nil) update(published_at: date || Time.current) end |
#published? ⇒ Boolean
76 77 78 |
# File 'app/models/spree/post.rb', line 76 def published? published_at.present? end |
#shortened_description ⇒ Object
92 93 94 95 |
# File 'app/models/spree/post.rb', line 92 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
65 66 67 |
# File 'app/models/spree/post.rb', line 65 def should_generate_new_friendly_id? slug.blank? || (persisted? && title_changed?) end |
#slug_candidates ⇒ Object
69 70 71 72 73 74 |
# File 'app/models/spree/post.rb', line 69 def slug_candidates [ :title, [:title, :id] ] end |
#unpublish ⇒ Object
84 85 86 |
# File 'app/models/spree/post.rb', line 84 def unpublish update(published_at: nil) end |