Class: Locomotive::ContentEntry
- Inherits:
-
Object
- Object
- Locomotive::ContentEntry
- Includes:
- CustomFields::Target, Extensions::ContentEntry::Csv, Extensions::ContentEntry::Localized, Extensions::Shared::Seo, Mongoid::Document
- Defined in:
- app/models/locomotive/content_entry.rb
Class Method Summary collapse
-
.drop_class ⇒ Object
All the content entries no matter the content type they belong to share the same liquid drop class.
-
.find_by_permalink(permalink) ⇒ Object
Find a content entry by its permalink.
-
.presenter_class ⇒ Object
All the content entries no matter the content type they belong to share the same presenter class.
-
.sort_entries!(ids, column = :_position) ⇒ Object
Sort the content entries from an ordered array of content entry ids.
Instance Method Summary collapse
-
#_label(type = nil) ⇒ String
(also: #to_label)
Any content entry owns a label property which is used in the back-office UI to represent it.
-
#_slug ⇒ Object
(also: #_permalink)
validations ##.
-
#next ⇒ Object
Return the next content entry based on the order defined in the parent content type.
-
#previous ⇒ Object
Return the previous content entry based on the order defined in the parent content type.
-
#site ⇒ Object
associations ##.
-
#visible ⇒ Object
named scopes ##.
Methods included from Extensions::ContentEntry::Localized
#localized?, #translated?, #translated_field?, #translated_in
Methods included from Extensions::ContentEntry::Csv
Class Method Details
.drop_class ⇒ Object
All the content entries no matter the content type they belong to share the same liquid drop class.
132 133 134 |
# File 'app/models/locomotive/content_entry.rb', line 132 def self.drop_class Locomotive::Liquid::Drops::ContentEntry end |
.find_by_permalink(permalink) ⇒ Object
Find a content entry by its permalink
99 100 101 |
# File 'app/models/locomotive/content_entry.rb', line 99 def self.find_by_permalink(permalink) self.where(_slug: permalink).first end |
.presenter_class ⇒ Object
All the content entries no matter the content type they belong to share the same presenter class.
123 124 125 |
# File 'app/models/locomotive/content_entry.rb', line 123 def self.presenter_class Locomotive::ContentEntryPresenter end |
.sort_entries!(ids, column = :_position) ⇒ Object
Sort the content entries from an ordered array of content entry ids. Their new positions are persisted.
109 110 111 112 113 114 115 116 |
# File 'app/models/locomotive/content_entry.rb', line 109 def self.sort_entries!(ids, column = :_position) list = self.any_in(_id: ids.map { |id| Moped::BSON::ObjectId.from_string(id.to_s) }).to_a ids.each_with_index do |id, position| if entry = list.detect { |e| e._id.to_s == id.to_s } entry.update_attributes column => position end end end |
Instance Method Details
#_label(type = nil) ⇒ String Also known as: to_label
Any content entry owns a label property which is used in the back-office UI to represent it. The field used as the label is defined within the parent content type.
65 66 67 68 69 70 71 72 73 |
# File 'app/models/locomotive/content_entry.rb', line 65 def _label(type = nil) value = if self._label_field_name self.send(self._label_field_name.to_sym) else self.send((type || self.content_type).label_field_name.to_sym) end value.respond_to?(:to_label) ? value.to_label : value.to_s end |
#_slug ⇒ Object Also known as: _permalink
validations ##
13 |
# File 'app/models/locomotive/content_entry.rb', line 13 field :_slug, localize: true |
#next ⇒ Object
Return the next content entry based on the order defined in the parent content type.
81 82 83 |
# File 'app/models/locomotive/content_entry.rb', line 81 def next next_or_previous :gt end |
#previous ⇒ Object
Return the previous content entry based on the order defined in the parent content type.
89 90 91 |
# File 'app/models/locomotive/content_entry.rb', line 89 def previous next_or_previous :lt end |
#site ⇒ Object
associations ##
23 |
# File 'app/models/locomotive/content_entry.rb', line 23 belongs_to :site, class_name: 'Locomotive::Site', validate: false, autosave: false |
#visible ⇒ Object
named scopes ##
35 |
# File 'app/models/locomotive/content_entry.rb', line 35 scope :visible, where(_visible: true) |