Sha256: f3097aa356c5001566fb66741611c730bdf789ec1ff40faad914e854603ac8d7

Contents?: true

Size: 1.3 KB

Versions: 69

Compression:

Stored size: 1.3 KB

Contents

module Plutonium
  module Helpers
    module TableHelper
      def attachment_preview_thumnail(attachment)
        return unless attachment.url.present?

        # Any changes made here must be reflected in attachment_input_controller#buildPreviewTemplate

        tag.div class: "bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700", data: {attachment_preview_target: "thumbnail"} do
          thumbnail_url = _attachment_thumbnail_url(attachment)
          link_body = if thumbnail_url
            image_tag thumbnail_url, style: "width:100%; height:100%; object-fit: contain;"
          else
            _attachment_extension(attachment)
          end

          link_to link_body, attachment.url, style: "width:150px; height:150px; line-height: 150px;",
            class: "d-block text-decoration-none user-select-none fs-5 font-monospace text-body-secondary",
            target: :blank,
            data: {attachment_preview_target: "thumbnailLink"}
        end
      end

      private

      def _attachment_thumbnail_url(attachment)
        attachment.url if attachment.representable?
      end

      def _attachment_extension(attachment)
        attachment.try(:extension) || File.extname(attachment.filename.to_s)
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
plutonium-0.19.2 lib/plutonium/helpers/table_helper.rb
plutonium-0.19.1 lib/plutonium/helpers/table_helper.rb
plutonium-0.19.0 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.8 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.7 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.6 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.5 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.4 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.3 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.2 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.1 lib/plutonium/helpers/table_helper.rb
plutonium-0.18.0 lib/plutonium/helpers/table_helper.rb
plutonium-0.16.5 lib/plutonium/helpers/table_helper.rb
plutonium-0.16.4 lib/plutonium/helpers/table_helper.rb
plutonium-0.16.3 lib/plutonium/helpers/table_helper.rb
plutonium-0.16.1 lib/plutonium/helpers/table_helper.rb
plutonium-0.16.0 lib/plutonium/helpers/table_helper.rb
plutonium-0.15.24 lib/plutonium/helpers/table_helper.rb
plutonium-0.15.23 lib/plutonium/helpers/table_helper.rb
plutonium-0.15.22 lib/plutonium/helpers/table_helper.rb