Class: Locomotive::ContentEntry

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Extensions::ContentEntry::Localized

#localized?, #translated?, #translated_field?, #translated_in

Methods included from Extensions::ContentEntry::Csv

#to_values

Class Method Details

.drop_classObject

All the content entries no matter the content type they belong to share the same liquid drop class.

Parameters:

  • The (Class)

    liquid drop class



119
120
121
# File 'app/models/locomotive/content_entry.rb', line 119

def self.drop_class
  Locomotive::Liquid::Drops::ContentEntry
end

Find a content entry by its permalink

Parameters:

Returns:

  • (Object)

    The content entry matching the permalink or nil if not found



86
87
88
# File 'app/models/locomotive/content_entry.rb', line 86

def self.find_by_permalink(permalink)
  self.where(_slug: permalink).first
end

.presenter_classObject

All the content entries no matter the content type they belong to share the same presenter class.

Parameters:

  • The (Class)

    content entry presenter class



110
111
112
# File 'app/models/locomotive/content_entry.rb', line 110

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.

Parameters:

  • content_type (Array)

    The content type describing the entries

  • The (Array)

    ordered array of ids



96
97
98
99
100
101
102
103
# File 'app/models/locomotive/content_entry.rb', line 96

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.

Parameters:

  • (optional) (Object)

    The content type to avoid to run another MongoDB and useless query.

Returns:

  • (String)

    The “label” of the content entry



52
53
54
55
56
57
58
59
60
# File 'app/models/locomotive/content_entry.rb', line 52

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

#_slugObject Also known as: _permalink

validations ##



13
# File 'app/models/locomotive/content_entry.rb', line 13

field :_slug,             localize: true

#nextObject

Return the next content entry based on the order defined in the parent content type.

Parameters:

  • The (Object)

    next content entry or nil if not found



68
69
70
# File 'app/models/locomotive/content_entry.rb', line 68

def next
  next_or_previous :gt
end

#previousObject

Return the previous content entry based on the order defined in the parent content type.

Parameters:

  • The (Object)

    previous content entry or nil if not found



76
77
78
# File 'app/models/locomotive/content_entry.rb', line 76

def previous
  next_or_previous :lt
end

#siteObject

associations ##



23
# File 'app/models/locomotive/content_entry.rb', line 23

belongs_to  :site,          class_name: 'Locomotive::Site', validate: false, autosave: false

#visibleObject

named scopes ##



35
# File 'app/models/locomotive/content_entry.rb', line 35

scope :visible, where(_visible: true)