Sha256: cf4f4540e0edbe5cad349ddca00c4107dddc4c2225814e14ce9f51c7539a09c5

Contents?: true

Size: 829 Bytes

Versions: 2

Compression:

Stored size: 829 Bytes

Contents

module Headmin
  module Form
    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 size
        number_to_human_size(attachment.blob&.byte_size || 0)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
headmin-0.5.5 app/models/headmin/form/media_item_view.rb
headmin-0.5.4 app/models/headmin/form/media_item_view.rb