Sha256: 84667b79043ff59f02e7867453be58c87aa3c4f3b191fba74fceebd020550262

Contents?: true

Size: 1010 Bytes

Versions: 15

Compression:

Stored size: 1010 Bytes

Contents

module Locomotive
  module API
    module Forms

      class EditableElementForm < BaseForm

        TYPES = %w(file text control)

        # Fix bug in Rails: http://stackoverflow.com/questions/18472876/instantiate-mongoid-subclasses-by-type-field
        TYPES.each do |type|
          "Locomotive::Editable#{type.classify}".constantize.inspect
        end

        attrs :_id, :_type, :block, :slug, :priority, :hint, :content

        def content=(value)
          if is_file?(value)
            self._type = :file
          end

          set_attribute :content, value
        end

        def _type=(type)
          return unless TYPES.include?(type.to_s)
          set_attribute :_type, "Locomotive::Editable#{type.to_s.classify}"
        end

        private

        def is_file?(value)
          value.respond_to?(:original_filename) ||
          (value.respond_to?(:key?) &&
            (value.key?(:original_filename) || value.key?(:tempfile))
          )
        end

      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.2.0.alpha1 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.1.1 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.1.0 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.1.0.rc1 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.0.3 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.0.2 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.0.1 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.0.0 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.0.0.rc0 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.0.0.alpha3 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-3.4.1 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.0.0.alpha2 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-4.0.0.alpha1 app/api/locomotive/api/forms/editable_element_form.rb
locomotivecms-3.4.0 app/api/locomotive/api/forms/editable_element_form.rb