Skip to content

Stop passing both presenter and document around #3588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions app/components/blacklight/document/thumbnail_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ class ThumbnailComponent < Blacklight::Component
# @param [Blacklight::DocumentPresenter] presenter
# @param [Integer] counter
# @param [Hash] image_options options for the thumbnail presenter's image tag
def initialize(counter:, presenter: nil, document: nil, image_options: {})
def initialize(counter:, presenter: nil, image_options: {})
@presenter = presenter
@document = presenter&.document || document
@counter = counter
@image_options = { alt: '' }.merge(image_options)
end

attr_accessor :presenter

def render?
presenter.thumbnail.exists?
end

def presenter
@presenter ||= helpers.document_presenter(@document)
end
end
end
end
6 changes: 3 additions & 3 deletions app/components/blacklight/document_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DocumentComponent < Blacklight::Component
renders_one :title, (lambda do |*args, component: nil, **kwargs|
component ||= view_config.title_component || Blacklight::DocumentTitleComponent

component.new(*args, counter: @counter, document: @document, presenter: @presenter, as: @title_component, actions: !@show, link_to_document: !@show, document_component: self, **kwargs)
component.new(*args, counter: @counter, presenter: @presenter, as: @title_component, actions: !@show, link_to_document: !@show, document_component: self, **kwargs)
end)

renders_one :embed, (lambda do |static_content = nil, *args, component: nil, **kwargs|
Expand All @@ -46,7 +46,7 @@ class DocumentComponent < Blacklight::Component

next unless component

component.new(*args, document: @document, presenter: @presenter, document_counter: @document_counter, **kwargs)
component.new(*args, presenter: @presenter, document_counter: @document_counter, **kwargs)
end)

# The primary metadata section
Expand All @@ -66,7 +66,7 @@ class DocumentComponent < Blacklight::Component

component ||= view_config.thumbnail_component || Blacklight::Document::ThumbnailComponent

component.new(*args, document: @document, presenter: @presenter, counter: @counter, image_options: image_options_or_static_content, **kwargs)
component.new(*args, presenter: @presenter, counter: @counter, image_options: image_options_or_static_content, **kwargs)
end)

# A container for partials rendered using the view config partials configuration. Its use is discouraged, but necessary until
Expand Down
13 changes: 3 additions & 10 deletions app/components/blacklight/document_title_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ class DocumentTitleComponent < Blacklight::Component
renders_many :actions

# rubocop:disable Metrics/ParameterLists
def initialize(title = nil, document: nil, presenter: nil, as: :h3, counter: nil, classes: 'index_title document-title-heading col h5', link_to_document: true, document_component: nil,
def initialize(title = nil, presenter:, as: :h3, counter: nil, classes: 'index_title document-title-heading col h5', link_to_document: true, document_component: nil,
actions: true)
raise ArgumentError, 'missing keyword: :document or :presenter' if presenter.nil? && document.nil?

@title = title
@document = document
@presenter = presenter
@as = as || :h3
@counter = counter
Expand All @@ -23,6 +20,8 @@ def initialize(title = nil, document: nil, presenter: nil, as: :h3, counter: nil
end
# rubocop:enable Metrics/ParameterLists

attr_accessor :presenter

# Content for the document title area; should be an inline element
def title
if @link_to_document
Expand Down Expand Up @@ -53,11 +52,5 @@ def counter
t('blacklight.search.documents.counter', counter: @counter)
end
end

private

def presenter
@presenter ||= helpers.document_presenter(@document)
end
end
end