Class: Locomotive::EditableText

Inherits:
EditableElement show all
Defined in:
app/models/locomotive/editable_text.rb

Direct Known Subclasses

EditableLongText, EditableShortText

Instance Attribute Summary

Attributes inherited from EditableElement

#block_name, #block_priority, #label

Instance Method Summary collapse

Methods inherited from EditableElement

#_type, #add_current_locale, #block_label, #by_priority, #disabled?, #page, #page_id, #path, #slug

Instance Method Details

#contentObject

fields ##



5
# File 'app/models/locomotive/editable_text.rb', line 5

field :content,         localize: true

#content=(value) ⇒ Object

Change the content of the editable element if the value is a new version. This method has been overridden for 2 reasons:

  • we have to register the current locale (localized site)

  • the default_content attribute has to be turned off

Called by:

  • the API: page with a YAML header defining the initial content for this editable element

  • the UI: if the content is the same as the default one or the previous one, don’t do anything.



25
26
27
28
29
30
# File 'app/models/locomotive/editable_text.rb', line 25

def content=(value)
  return if value == self.content
  self.add_current_locale
  self.default_content = false
  super
end

#content_from_default=(content) ⇒ Object



36
37
38
39
40
41
42
# File 'app/models/locomotive/editable_text.rb', line 36

def content_from_default=(content)
  if self.default_content?
    self.content_will_change!
    self.attributes['content'] ||= {}
    self.attributes['content'][::Mongoid::Fields::I18n.locale.to_s] = content
  end
end

#default_content?Boolean

Returns:



32
33
34
# File 'app/models/locomotive/editable_text.rb', line 32

def default_content?
  !!self.default_content
end