Class: Koi::Tables::Cells::AttachmentComponent
- Inherits:
-
Katalyst::Tables::CellComponent
- Object
- Katalyst::Tables::CellComponent
- Koi::Tables::Cells::AttachmentComponent
- Defined in:
- app/components/koi/tables/cells/attachment_component.rb
Overview
Shows an attachment
The value is expected to be an ActiveStorage attachment
If it is representable, shows as a image tag using the specified variant.
Otherwise shows as a link to download.
Instance Method Summary collapse
- #filename ⇒ Object
-
#initialize(variant:) ⇒ AttachmentComponent
constructor
A new instance of AttachmentComponent.
-
#internal_path ⇒ Object
Utility for accessing the path Rails provides for retrieving the attachment for use in cells.
- #rendered_value ⇒ Object
- #representation ⇒ Object
Constructor Details
#initialize(variant:) ⇒ AttachmentComponent
Returns a new instance of AttachmentComponent.
14 15 16 17 18 |
# File 'app/components/koi/tables/cells/attachment_component.rb', line 14 def initialize(variant:, **) super(**) @variant = variant end |
Instance Method Details
#filename ⇒ Object
34 35 36 |
# File 'app/components/koi/tables/cells/attachment_component.rb', line 34 def filename value.blob.filename end |
#internal_path ⇒ Object
Utility for accessing the path Rails provides for retrieving the attachment for use in cells. Example:
<% row.attachment :file do |cell| %>
<%= link_to "Download", cell.internal_path %>
<% end %>
43 44 45 |
# File 'app/components/koi/tables/cells/attachment_component.rb', line 43 def internal_path rails_blob_path(value, disposition: :attachment) end |
#rendered_value ⇒ Object
20 21 22 |
# File 'app/components/koi/tables/cells/attachment_component.rb', line 20 def rendered_value representation end |
#representation ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/components/koi/tables/cells/attachment_component.rb', line 24 def representation if value.try(:variable?) && named_variant.present? image_tag(value.variant(@variant)) elsif value.try(:attached?) filename.to_s else "" end end |