Sha256: eb47750981394b0e62c215be9bd1d18c0d9ae9e87507768be575436107604c5e

Contents?: true

Size: 831 Bytes

Versions: 2

Compression:

Stored size: 831 Bytes

Contents

module Satis
  module Attachments
    class Component < Satis::ApplicationComponent
      include Rails.application.routes.url_helpers

      attr_reader :model, :attribute, :attachments_options

      def initialize(model, attribute, **options)
        super()
        @model = model
        @attribute = attribute
        @attachments_options = options
      end

      def model_has_images
        model.respond_to?(:images)
      end

      def attachment_style(attachment)
        if attachment.representable?
          url = attachment.representation(resize_to_limit: [200, 200]).processed.url
          "background-image: url(#{url})"
        else
          "background-color: f0f0f0"
        end
      end


      def model_sgid
        @model.to_sgid(expires_in: nil, for: 'satis_attachments')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
satis-2.1.48 app/components/satis/attachments/component.rb
satis-2.1.47 app/components/satis/attachments/component.rb