Sha256: c248eb28a2b6c46f145ed1d91aad49976bfd43e7250cb7c1e5c85021f6e3b4c5

Contents?: true

Size: 784 Bytes

Versions: 19

Compression:

Stored size: 784 Bytes

Contents

module Locomotive
  class EditableControl < EditableElement

    ## fields ##
    field :content
    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

19 entries across 19 versions & 1 rubygems

Version Path
locomotivecms-3.1.2 app/models/locomotive/editable_control.rb
locomotivecms-3.2.0.rc2 app/models/locomotive/editable_control.rb
locomotivecms-3.2.0.rc1 app/models/locomotive/editable_control.rb
locomotivecms-3.1.1 app/models/locomotive/editable_control.rb
locomotivecms-3.1.0 app/models/locomotive/editable_control.rb
locomotivecms-3.1.0.rc3 app/models/locomotive/editable_control.rb
locomotivecms-3.1.0.rc2 app/models/locomotive/editable_control.rb
locomotivecms-3.1.0.rc1 app/models/locomotive/editable_control.rb
locomotivecms-3.0.1 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.rc7 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.rc6 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.rc5 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.rc4 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.rc3 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.rc2 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.rc1 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.pre.beta.1 app/models/locomotive/editable_control.rb
locomotivecms-3.0.0.pre.alpha.3 app/models/locomotive/editable_control.rb