Class: Locomotive::EditableElement

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/locomotive/editable_element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#block_nameObject

non-persisted attributes ##


30
31
32
# File 'app/models/locomotive/editable_element.rb', line 30

def block_name
  @block_name
end

#block_priorityObject

non-persisted attributes ##


30
31
32
# File 'app/models/locomotive/editable_element.rb', line 30

def block_priority
  @block_priority
end

#labelObject

methods ##


30
31
32
# File 'app/models/locomotive/editable_element.rb', line 30

def label
  @label
end

Instance Method Details

#_typeObject


50
51
52
# File 'app/models/locomotive/editable_element.rb', line 50

def _type
  nil
end

#add_current_localeObject

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.


62
63
64
65
# File 'app/models/locomotive/editable_element.rb', line 62

def add_current_locale
  locale = ::Mongoid::Fields::I18n.locale.to_s
  self.locales << locale unless self.locales.include?(locale)
end

#block_labelObject


38
39
40
# File 'app/models/locomotive/editable_element.rb', line 38

def block_label
  (@block_name || self.block).try(:humanize)
end

#by_priorityObject

scopes ##


26
# File 'app/models/locomotive/editable_element.rb', line 26

scope :by_priority,         -> { order_by(priority: :desc) }

#disabled?Boolean

Returns:


46
47
48
# File 'app/models/locomotive/editable_element.rb', line 46

def disabled?
  !!self.disabled # the original method does not work quite well with the localization
end

#pageObject

associations ##


18
# File 'app/models/locomotive/editable_element.rb', line 18

embedded_in :page, class_name: 'Locomotive::Page', inverse_of: :editable_elements

#page_idObject


54
55
56
# File 'app/models/locomotive/editable_element.rb', line 54

def page_id
  self._parent.try(:_id)
end

#pathObject


42
43
44
# File 'app/models/locomotive/editable_element.rb', line 42

def path
  [block, slug].compact.join('--').gsub('/', '--')
end

#slugObject

validations ##


7
# File 'app/models/locomotive/editable_element.rb', line 7

field :slug