Skip to content

Commit

Permalink
Add attachment component to summary list
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCornthwaiteKatalyst committed Feb 9, 2024
1 parent 73bc0c7 commit 074a2c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
11 changes: 11 additions & 0 deletions app/components/koi/summary_list/attachment_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Koi
module SummaryList
class AttachmentComponent < Base
def attribute_value
link_to raw_value.blob.filename, rails_blob_path(raw_value, disposition: :attachment)
end
end
end
end
19 changes: 12 additions & 7 deletions app/components/koi/summary_list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ class SummaryListComponent < ViewComponent::Base
include Katalyst::HtmlAttributes

renders_many :definitions, types: {
boolean: SummaryList::BooleanComponent,
date: SummaryList::DateComponent,
datetime: SummaryList::DatetimeComponent,
number: SummaryList::NumberComponent,
rich_text: SummaryList::RichTextComponent,
text: SummaryList::TextComponent,
boolean: SummaryList::BooleanComponent,
date: SummaryList::DateComponent,
datetime: SummaryList::DatetimeComponent,
number: SummaryList::NumberComponent,
rich_text: SummaryList::RichTextComponent,
text: SummaryList::TextComponent,
attachment: SummaryList::AttachmentComponent,

# @deprecated legacy interface
item: SummaryList::ItemComponent,
item: SummaryList::ItemComponent,
}

def initialize(model: nil, skip_blank: true, **attributes)
Expand Down Expand Up @@ -47,6 +48,10 @@ def text(attribute, label: nil, skip_blank: @skip_blank)
with_definition_text(@model, attribute, label:, skip_blank:)
end

def attachment(attribute, label: nil, skip_blank: @skip_blank)
with_definition_attachment(@model, attribute, label:, skip_blank:)
end

# @deprecated legacy interface
def item(model, attribute, label: nil, skip_blank: @skip_blank, &)
with_definition_item(model, attribute, label:, skip_blank:, &)
Expand Down

0 comments on commit 074a2c1

Please sign in to comment.