Skip to content

Commit

Permalink
redo
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaLMoore committed Nov 14, 2024
1 parent 13ce199 commit 7a02033
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 72 deletions.
15 changes: 8 additions & 7 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ def group_navigation_presenter
# - fallback to Hyrax's default image
def collection_thumbnail(document, _image_options = {}, url_options = {})
view_class = url_options[:class]
# Use collection branding thumbnail if it exists
if document['thumbnail_path_ss'].present? && !document['thumbnail_path_ss'].include?('default_work_images')
return image_tag(document['thumbnail_path_ss'], class: view_class, alt: alttext_for(document))
end
# The correct thumbnail SHOULD be indexed on the object
return image_tag(document['thumbnail_path_ss'], class: view_class, alt: alttext_for(document)) if document['thumbnail_path_ss'].present?

# If no branding thumbnail, use the site's default collection image
return image_tag(Site.instance.default_collection_image.url, alt: alttext_for(document), class: view_class) if Site.instance.default_collection_image.present?
# If nothing is indexed, we just fall back to site default
return image_tag(Site.instance.default_collection_image&.url, alt: alttext_for(document), class: view_class) if Site.instance.default_collection_image.present?

# Fallback to Hyrax's default image if no site default
# fall back to Hyrax default if no site default
tag.span("", class: [Hyrax::ModelIcon.css_class_for(::Collection), view_class],
alt: alttext_for(document))
end
Expand All @@ -43,6 +41,7 @@ def alttext_for(collection)

def hint_for(term:, record_class: nil)
hint = locale_for(type: 'hints', term:, record_class:)

return hint unless missing_translation(hint)
end

Expand All @@ -51,6 +50,7 @@ def locale_for(type:, term:, record_class:)
record_class = record_class.to_s.downcase
work_or_collection = record_class == Hyrax.config.collection_model.downcase ? 'collection' : 'defaults'
locale = t("hyrax.#{record_class}.#{type}.#{term}")

if missing_translation(locale)
(t("simple_form.#{type}.#{work_or_collection}.#{term}")).try(:html_safe)
else
Expand All @@ -66,6 +66,7 @@ def missing_translation(value, _options = {})

def markdown(text)
return text unless Flipflop.treat_some_user_inputs_as_markdown?

# Consider extracting these options to a Hyku::Application
# configuration/class attribute.
options = %i[
Expand Down
8 changes: 4 additions & 4 deletions app/services/hyrax/thumbnail_path_service_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def call(object)
collection_thumbnail = CollectionBrandingInfo.where(collection_id: object.id.to_s, role: "thumbnail").first
return collection_thumbnail.local_path.gsub(Hyrax.config.branding_path.to_s, '/branding') if collection_thumbnail

# Fallback to site-wide default collection image if no branding thumbnail
return default_collection_image if !object.respond_to?(:thumbnail_id) || object.thumbnail_id.blank?
if object.try(:thumbnail_id).blank?
return default_collection_image if object.try(:collection?)
return default_image
end

# Retrieve thumbnail if it exists, otherwise use the default collection image
thumb = fetch_thumbnail(object)
return default_collection_image unless thumb

# Process thumbnail for audio or default image types
return call(thumb) unless thumb.file_set?
if audio?(thumb)
audio_image
Expand Down
64 changes: 3 additions & 61 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

RSpec.describe ApplicationHelper, type: :helper do
describe "#markdown" do
let(:header) { '# header' }
Expand All @@ -7,6 +8,7 @@
context 'when treat_some_user_inputs_as_markdown is true' do
it 'renders markdown into html' do
allow(Flipflop).to receive(:treat_some_user_inputs_as_markdown?).and_return(true)

expect(helper.markdown(header)).to eq("<h1>header</h1>\n")
expect(helper.markdown(bold)).to eq("<p><em>bold</em></p>\n")
end
Expand All @@ -15,6 +17,7 @@
context 'when treat_some_user_inputs_as_markdown is false' do
it 'does not render markdown into html' do
allow(Flipflop).to receive(:treat_some_user_inputs_as_markdown?).and_return(false)

expect(helper.markdown(header)).to eq('# header')
expect(helper.markdown(bold)).to eq('*bold*')
end
Expand All @@ -28,65 +31,4 @@
end
end
end

describe '#collection_thumbnail' do
let(:document) { instance_double('SolrDocument', id: '123', title_or_label: 'Test Collection') }
let(:url_options) { { class: 'view-class' } }

context 'when collection has a branding thumbnail' do
before do
allow(document).to receive(:[]).with('thumbnail_path_ss').and_return('/path/to/thumbnail.jpg')
end

it 'returns the branding thumbnail image tag' do
expect(helper.collection_thumbnail(document, {}, url_options)).to include('src="/path/to/thumbnail.jpg"')
expect(helper.collection_thumbnail(document, {}, url_options)).to include('class="view-class"')
end
end

context 'when collection has no branding thumbnail but site has default image' do
let(:site_instance) { instance_double('Site') }
let(:default_image) { instance_double('DefaultImage', url: '/default/image.jpg') }

before do
allow(document).to receive(:[]).with('thumbnail_path_ss').and_return(nil)
allow(Site).to receive(:instance).and_return(site_instance)
allow(site_instance).to receive(:default_collection_image).and_return(default_image)
allow(site_instance).to receive(:default_collection_image).and_return(default_image)
end

it 'returns the site default collection image tag' do
expect(helper.collection_thumbnail(document, {}, url_options)).to include('src="/default/image.jpg"')
expect(helper.collection_thumbnail(document, {}, url_options)).to include('class="view-class"')
end
end

context 'when collection has no branding thumbnail and no site default image' do
before do
allow(document).to receive(:[]).with('thumbnail_path_ss').and_return(nil)
allow(Site).to receive(:instance).and_return(instance_double('Site', default_collection_image: nil))
allow(Hyrax::ModelIcon).to receive(:css_class_for).with(::Collection).and_return('collection-icon-class')
end

it 'returns the Hyrax default icon span' do
result = helper.collection_thumbnail(document, {}, url_options)
expect(result).to include('class="collection-icon-class view-class"')
expect(result).to include('<span')
end
end

context 'when thumbnail path includes default_work_images' do
before do
allow(document).to receive(:[]).with('thumbnail_path_ss').and_return('/default_work_images/thumb.jpg')
allow(Site).to receive(:instance).and_return(instance_double('Site', default_collection_image: nil))
allow(Hyrax::ModelIcon).to receive(:css_class_for).with(::Collection).and_return('collection-icon-class')
end

it 'falls back to Hyrax default icon' do
result = helper.collection_thumbnail(document, {}, url_options)
expect(result).to include('class="collection-icon-class view-class"')
expect(result).to include('<span')
end
end
end
end

0 comments on commit 7a02033

Please sign in to comment.