Sha256: d59b0020ce555366c14ce00264c8c5fbbb4d3a558d767ce477e6430016ca247d

Contents?: true

Size: 1.5 KB

Versions: 18

Compression:

Stored size: 1.5 KB

Contents

module Locomotive
  class EditableText < EditableElement

    ## fields ##
    field :content,         localize: true
    field :default_content, type: Boolean, localize: true, default: true
    field :format,          default: 'html'
    field :rows,            type: Integer, default: 15
    field :inline,          type: Boolean, default: false
    field :line_break,      type: Boolean, default: true # deprecated

    ## callbacks ##
    before_save :strip_content

    ## methods ##

    # 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.
    def content=(value)
      return if value == self.content
      self.add_current_locale
      self.default_content = false
      super
    end

    def default_content?
      !!self.default_content
    end

    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

    protected

    def strip_content
      self.content.strip! unless self.content.blank?
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/models/locomotive/editable_text.rb
locomotivecms-4.2.0.alpha1 app/models/locomotive/editable_text.rb
locomotivecms-4.1.1 app/models/locomotive/editable_text.rb
locomotivecms-4.1.0 app/models/locomotive/editable_text.rb
locomotivecms-4.1.0.rc1 app/models/locomotive/editable_text.rb
locomotivecms-4.0.3 app/models/locomotive/editable_text.rb
locomotivecms-4.0.2 app/models/locomotive/editable_text.rb
locomotivecms-4.0.1 app/models/locomotive/editable_text.rb
locomotivecms-4.0.0 app/models/locomotive/editable_text.rb
locomotivecms-4.0.0.rc0 app/models/locomotive/editable_text.rb
locomotivecms-4.0.0.alpha3 app/models/locomotive/editable_text.rb
locomotivecms-3.4.1 app/models/locomotive/editable_text.rb
locomotivecms-4.0.0.alpha2 app/models/locomotive/editable_text.rb
locomotivecms-4.0.0.alpha1 app/models/locomotive/editable_text.rb
locomotivecms-3.4.0 app/models/locomotive/editable_text.rb
locomotivecms-3.3.0 app/models/locomotive/editable_text.rb
locomotivecms-3.3.0.rc3 app/models/locomotive/editable_text.rb
locomotivecms-3.3.0.rc2 app/models/locomotive/editable_text.rb