Sha256: 7bd50be67d6b2f54f96e362c906551b99ac1f026ace2b28258d64037845f24ab
Contents?: true
Size: 1.55 KB
Versions: 2
Compression:
Stored size: 1.55 KB
Contents
module Locomotive class EditableElement include Locomotive::Mongoid::Document ## fields ## field :slug field :block field :content, localize: true field :hint field :priority, type: Integer, default: 0 field :fixed, type: Boolean, default: false field :disabled, type: Boolean, default: false, localize: true field :from_parent, type: Boolean, default: false field :locales, type: Array, default: [] ## associations ## embedded_in :page, class_name: 'Locomotive::Page', inverse_of: :editable_elements ## validations ## validates_presence_of :slug ## callbacks ## ## scopes ## scope :by_priority, -> { order_by(priority: :desc) } scope :by_block_and_slug, ->(block, slug) { where(block: block, slug: slug) } ## non-persisted attributes ## attr_accessor :block_name, :block_priority ## methods ## def label self.slug end def block_label (@block_name || self.block).try(:humanize) end def disabled? !!self.disabled # the original method does not work quite well with the localization end def _type nil end def page_id self._parent.try(:_id) end # Make sure the current locale is added to the list # of locales for the current element so that we know # in which languages the element was translated. # def add_current_locale locale = ::Mongoid::Fields::I18n.locale.to_s self.locales << locale unless self.locales.include?(locale) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
locomotivecms-3.0.0.rc4 | app/models/locomotive/editable_element.rb |
locomotivecms-3.0.0.rc3 | app/models/locomotive/editable_element.rb |