Class: Locomotive::ContentEntry
- Inherits:
-
Object
- Object
- Locomotive::ContentEntry
- Includes:
- CustomFields::Target, Locomotive::Concerns::ContentEntry::Counter, Locomotive::Concerns::ContentEntry::Csv, Locomotive::Concerns::ContentEntry::FileSize, Locomotive::Concerns::ContentEntry::Localized, Locomotive::Concerns::ContentEntry::NextPrevious, Locomotive::Concerns::ContentEntry::Slug, Locomotive::Concerns::Shared::Seo, Locomotive::Concerns::Shared::SiteScope, Locomotive::Concerns::Shared::Userstamp, Mongoid::Document
- Defined in:
- app/models/locomotive/content_entry.rb
Class Method Summary collapse
-
.find_by_id_or_permalink(id_or_permalink) ⇒ Object
Find a content entry by its permalink or its id.
-
.find_by_permalink(permalink) ⇒ Object
Find a content entry by its permalink.
-
.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 ##.
- #as_json(*args) ⇒ Object
-
#content_type ⇒ Object
associations ##.
- #content_type_slug ⇒ Object
- #to_liquid(type = nil) ⇒ Object
- #to_steam(type = nil) ⇒ Object
- #touch_site_attribute ⇒ Object
-
#visible ⇒ Object
named scopes ##.
Methods included from Locomotive::Concerns::ContentEntry::NextPrevious
Methods included from Locomotive::Concerns::ContentEntry::Localized
#localized?, #translated?, #translated_field?, #translated_in
Methods included from Locomotive::Concerns::ContentEntry::Csv
Class Method Details
.find_by_id_or_permalink(id_or_permalink) ⇒ Object
Find a content entry by its permalink or its id
104 105 106 |
# File 'app/models/locomotive/content_entry.rb', line 104 def self.find_by_id_or_permalink(id_or_permalink) any_of({ _id: id_or_permalink }, { _slug: id_or_permalink }).first end |
.find_by_permalink(permalink) ⇒ Object
Find a content entry by its permalink
94 95 96 |
# File 'app/models/locomotive/content_entry.rb', line 94 def self.find_by_permalink(permalink) self.where(_slug: permalink).first end |
.sort_entries!(ids, column = :_position) ⇒ Object
Sort the content entries from an ordered array of content entry ids. Their new positions are persisted.
114 115 116 117 118 119 120 121 |
# File 'app/models/locomotive/content_entry.rb', line 114 def self.sort_entries!(ids, column = :_position) list = self.any_in(_id: ids.map { |id| 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.set 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.
72 73 74 75 76 |
# File 'app/models/locomotive/content_entry.rb', line 72 def _label(type = nil) value = self.send(_label_field_name(type)) value.respond_to?(:to_label) ? value.to_label : value.to_s end |
#_slug ⇒ Object Also known as: _permalink
validations ##
19 |
# File 'app/models/locomotive/content_entry.rb', line 19 field :_slug, localize: true |
#as_json(*args) ⇒ Object
84 85 86 |
# File 'app/models/locomotive/content_entry.rb', line 84 def as_json(*args) super.tap { |json| json['_label'] = _label } end |
#content_type ⇒ Object
associations ##
28 |
# File 'app/models/locomotive/content_entry.rb', line 28 belongs_to :content_type, class_name: 'Locomotive::ContentType', inverse_of: :entries, custom_fields_parent_klass: true |
#content_type_slug ⇒ Object
80 81 82 |
# File 'app/models/locomotive/content_entry.rb', line 80 def content_type_slug self.content_type.try(:slug) end |
#to_liquid(type = nil) ⇒ Object
127 128 129 |
# File 'app/models/locomotive/content_entry.rb', line 127 def to_liquid(type = nil) to_steam(type).to_liquid end |
#to_steam(type = nil) ⇒ Object
123 124 125 |
# File 'app/models/locomotive/content_entry.rb', line 123 def to_steam(type = nil) (type || self.content_type).to_steam_entry(self) end |
#touch_site_attribute ⇒ Object
131 132 133 |
# File 'app/models/locomotive/content_entry.rb', line 131 def touch_site_attribute :content_version end |
#visible ⇒ Object
named scopes ##
36 |
# File 'app/models/locomotive/content_entry.rb', line 36 scope :visible, -> { where(_visible: true) } |