Class: Koi::SummaryList::AttachmentComponent
- Defined in:
- app/components/koi/summary_list/attachment_component.rb
Instance Method Summary collapse
- #attribute_value ⇒ Object
- #filename ⇒ Object
-
#initialize(model, attribute, variant: :thumb, **attributes) ⇒ 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.
- #representation ⇒ Object
Methods inherited from Base
#attribute_name, #call, #inspect, #raw_value, #render?, #to_s
Constructor Details
#initialize(model, attribute, variant: :thumb, **attributes) ⇒ AttachmentComponent
Returns a new instance of AttachmentComponent.
6 7 8 9 10 |
# File 'app/components/koi/summary_list/attachment_component.rb', line 6 def initialize(model, attribute, variant: :thumb, **attributes) super(model, attribute, **attributes) @variant = variant end |
Instance Method Details
#attribute_value ⇒ Object
12 13 14 |
# File 'app/components/koi/summary_list/attachment_component.rb', line 12 def attribute_value representation end |
#filename ⇒ Object
26 27 28 |
# File 'app/components/koi/summary_list/attachment_component.rb', line 26 def filename raw_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 %>
35 36 37 |
# File 'app/components/koi/summary_list/attachment_component.rb', line 35 def internal_path rails_blob_path(raw_value, disposition: :attachment) end |
#representation ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'app/components/koi/summary_list/attachment_component.rb', line 16 def representation if raw_value.try(:variable?) && named_variant.present? image_tag(raw_value.variant(@variant)) elsif raw_value.try(:attached?) filename.to_s else "" end end |