Class: Locomotive::ContentEntry
- Inherits:
-
Object
- Object
- Locomotive::ContentEntry
- Includes:
- CustomFields::Target, Locomotive::Concerns::ContentEntry::Authentication, 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::Authentication
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
105 106 107 |
# File 'app/models/locomotive/content_entry.rb', line 105 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
95 96 97 |
# File 'app/models/locomotive/content_entry.rb', line 95 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.
115 116 117 118 119 120 121 122 |
# File 'app/models/locomotive/content_entry.rb', line 115 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.
73 74 75 76 77 |
# File 'app/models/locomotive/content_entry.rb', line 73 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 ##
20 |
# File 'app/models/locomotive/content_entry.rb', line 20 field :_slug, localize: true |
#as_json(*args) ⇒ Object
85 86 87 |
# File 'app/models/locomotive/content_entry.rb', line 85 def as_json(*args) super.tap { |json| json['_label'] = _label } end |
#content_type ⇒ Object
associations ##
29 |
# File 'app/models/locomotive/content_entry.rb', line 29 belongs_to :content_type, class_name: 'Locomotive::ContentType', inverse_of: :entries, custom_fields_parent_klass: true |
#content_type_slug ⇒ Object
81 82 83 |
# File 'app/models/locomotive/content_entry.rb', line 81 def content_type_slug self.content_type.try(:slug) end |
#to_liquid(type = nil) ⇒ Object
128 129 130 |
# File 'app/models/locomotive/content_entry.rb', line 128 def to_liquid(type = nil) to_steam(type).to_liquid end |
#to_steam(type = nil) ⇒ Object
124 125 126 |
# File 'app/models/locomotive/content_entry.rb', line 124 def to_steam(type = nil) (type || self.content_type).to_steam_entry(self) end |
#touch_site_attribute ⇒ Object
132 133 134 |
# File 'app/models/locomotive/content_entry.rb', line 132 def touch_site_attribute :content_version end |
#visible ⇒ Object
named scopes ##
37 |
# File 'app/models/locomotive/content_entry.rb', line 37 scope :visible, -> { where(_visible: true) } |