Class: Locomotive::EditableText

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

Direct Known Subclasses

EditableLongText, EditableShortText

Instance Method Summary collapse

Methods inherited from EditableElement

#_run_rearrange_callbacks, #add_current_locale, #by_priority, #copy_attributes, #disabled?, #disabled_in_all_translations?, #editable?, #page, #slug

Instance Method Details

#contentObject

fields ##



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

field :content,         localize: true

#content=(value) ⇒ Object

methods ##



16
17
18
19
20
21
# File 'app/models/locomotive/editable_text.rb', line 16

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

#content_from_default=(content) ⇒ Object



27
28
29
30
31
32
33
# File 'app/models/locomotive/editable_text.rb', line 27

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

#copy_attributes_from(el) ⇒ Object



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

def copy_attributes_from(el)
  super(el)

  self.copy_formatting_attributes_from(el)

  self.attributes['content']          = el.content_translations || {}
  self.attributes['default_content']  = el.default_content_translations
end

#copy_default_attributes_from(el) ⇒ Object



44
45
46
47
48
# File 'app/models/locomotive/editable_text.rb', line 44

def copy_default_attributes_from(el)
  super(el)

  self.copy_formatting_attributes_from(el)
end

#copy_formatting_attributes_from(el) ⇒ Object



50
51
52
53
54
# File 'app/models/locomotive/editable_text.rb', line 50

def copy_formatting_attributes_from(el)
  %w(format rows line_break).each do |attr|
    self.attributes[attr] = el.attributes[attr]
  end
end

#default_content?Boolean

Returns:



23
24
25
# File 'app/models/locomotive/editable_text.rb', line 23

def default_content?
  !!self.default_content
end

#set_default_content_from(el) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/locomotive/editable_text.rb', line 56

def set_default_content_from(el)
  super(el)

  locale = ::Mongoid::Fields::I18n.locale.to_s

  if self.default_content? || self.attributes['default_content'][locale].nil?
    self.default_content = true

    self.content_will_change!

    if self.attributes['content']
      self.attributes['content'][locale] = el.content
    end
  end
end