Sha256: fd105d9063a17b88296ceeaa162f1d9d0dd4786c034a93dd72e21de3190902ff

Contents?: true

Size: 823 Bytes

Versions: 16

Compression:

Stored size: 823 Bytes

Contents

module Formstrap
  class MediaItemView < ViewModel
    include Rails.application.routes.url_helpers

    def thumbnail_options
      options = {
        file: attachment
      }

      # Don't pass width or height if it was not defined
      options = options.merge(width: width) if is_defined?(:width)
      options = options.merge(height: height) if is_defined?(:height)

      options
    end

    def attachment
      form.object
    end

    def position_value
      attachment.new_record? ? nil : attachment.position
    end

    def id
      attachment.blob ? attachment.blob.id : "$1"
    end

    def filename
      attachment.blob&.filename&.to_s
    end

    def content_type
      attachment.blob&.content_type
    end

    def size
      number_to_human_size(attachment.blob&.byte_size || 0)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
formstrap-0.4.5 app/models/formstrap/media_item_view.rb
formstrap-0.4.4 app/models/formstrap/media_item_view.rb
formstrap-0.4.3 app/models/formstrap/media_item_view.rb
formstrap-0.4.2 app/models/formstrap/media_item_view.rb
formstrap-0.3.5 app/models/formstrap/media_item_view.rb
formstrap-0.3.4 app/models/formstrap/media_item_view.rb
formstrap-0.3.3 app/models/formstrap/media_item_view.rb
formstrap-0.3.2 app/models/formstrap/media_item_view.rb
formstrap-0.3.1 app/models/formstrap/media_item_view.rb
formstrap-0.3.0 app/models/formstrap/media_item_view.rb
formstrap-0.2.1 app/models/formstrap/media_item_view.rb
formstrap-0.2.0 app/models/formstrap/media_item_view.rb
formstrap-0.1.3 app/models/formstrap/media_item_view.rb
formstrap-0.1.2 app/models/formstrap/media_item_view.rb
formstrap-0.1.1 app/models/formstrap/media_item_view.rb
formstrap-0.1.0 app/models/formstrap/media_item_view.rb