Sha256: d6cc8d0323558c21fdacbd82df76672b1018875e4d555a93d517589203a5b9ec

Contents?: true

Size: 800 Bytes

Versions: 21

Compression:

Stored size: 800 Bytes

Contents

module Locomotive
  class EditableControl < EditableElement

    ## fields ##
    field :content, localize: true
    field :default_content, type: Boolean, default: true
    field :options, type: Array, default: []

    ## methods ##

    def options=(value)
      if value.respond_to?(:split)
        value = value.split(/\s*\,\s*/).map do |option|
          first, last = *option.split(/\s*=\s*/)
          last ||= first
          { 'value' => first, 'text' => last }
        end
      end

      super(value)
    end

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

    def content_from_default=(content)
      if self.default_content?
        self.content = content.to_s
      end
    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

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