Class: Locomotive::ContentEntry
- Inherits:
-
Object
- Object
- Locomotive::ContentEntry
- Includes:
- CustomFields::Target, Extensions::Shared::Seo, Mongoid::Document
- Defined in:
- app/models/locomotive/content_entry.rb
Class Method Summary collapse
-
.find_by_permalink(permalink) ⇒ Object
Find a content entry by its permalink.
-
.sort_entries!(ids) ⇒ 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 ##.
-
#translated? ⇒ Boolean
Tell if the content entry has been translated or not.
-
#translated_in ⇒ Array
Return the locales the content entry has been translated to.
-
#visible ⇒ Object
named scopes ##.
Class Method Details
.find_by_permalink(permalink) ⇒ Object
Find a content entry by its permalink
107 108 109 |
# File 'app/models/locomotive/content_entry.rb', line 107 def self.find_by_permalink(permalink) self.where(:_slug => permalink).first end |
.sort_entries!(ids) ⇒ Object
Sort the content entries from an ordered array of content entry ids. Their new positions are persisted.
116 117 118 119 120 121 122 123 |
# File 'app/models/locomotive/content_entry.rb', line 116 def self.sort_entries!(ids) 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.update_attributes :_position => 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.
48 49 50 51 52 53 54 55 56 |
# File 'app/models/locomotive/content_entry.rb', line 48 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 ##
11 |
# File 'app/models/locomotive/content_entry.rb', line 11 field :_slug |
#next ⇒ Object
Return the next 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 next next_or_previous :gt end |
#previous ⇒ Object
Return the previous content entry based on the order defined in the parent content type.
97 98 99 |
# File 'app/models/locomotive/content_entry.rb', line 97 def previous next_or_previous :lt end |
#site ⇒ Object
associations ##
20 |
# File 'app/models/locomotive/content_entry.rb', line 20 belongs_to :site, :class_name => 'Locomotive::Site' |
#translated? ⇒ Boolean
Tell if the content entry has been translated or not. It just checks if the field used for the label has been translated.
65 66 67 68 69 70 71 |
# File 'app/models/locomotive/content_entry.rb', line 65 def translated? if self.respond_to?(:"#{self._label_field_name}_translations") self.send(:"#{self._label_field_name}_translations").key?(::Mongoid::Fields::I18n.locale.to_s) #rescue false else true end end |
#translated_in ⇒ Array
Return the locales the content entry has been translated to.
77 78 79 80 81 82 83 |
# File 'app/models/locomotive/content_entry.rb', line 77 def translated_in if self.respond_to?(:"#{self._label_field_name}_translations") self.send(:"#{self._label_field_name}_translations").keys else nil end end |
#visible ⇒ Object
named scopes ##
32 |
# File 'app/models/locomotive/content_entry.rb', line 32 scope :visible, :where => { :_visible => true } |