Skip to content

Commit

Permalink
Update to use new view_component slot API
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 9, 2023
1 parent 0eb6dee commit 03721c4
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Blacklight::DocumentComponent.new(classes: 'col', component: :div, document: @document, presenter: @presenter, counter: @counter)
%>
<%= render(component) do |component| %>
<% component.body do %>
<% component.with_body do %>
<div class="thumbnail-container">
<%= thumbnail %>

Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/gallery/document_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Blacklight
module Gallery
class DocumentComponent < Blacklight::DocumentComponent
def before_render
thumbnail(image_options: { class: 'img-thumbnail' }) unless thumbnail.present?
with_thumbnail(image_options: { class: 'img-thumbnail' }) unless thumbnail.present?
super
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Blacklight::DocumentComponent.new(classes: 'slideshow-preview-thumbnail', component: :div, document: @document, presenter: @presenter, counter: @counter)
%>
<%= render(component) do |component| %>
<% component.body do %>
<%= @view_context.link_to_document(@document, thumbnail, class: 'thumbnail', data: { 'context-href': nil, 'slide-to': @document_counter - 1, toggle: "modal", target: "#slideshow-modal" }) %>
<% component.with_body do %>
<%= @view_context.link_to_document(@document, thumbnail, class: 'thumbnail', data: { 'context-href': nil, 'slide-to': @document_counter, toggle: "modal", target: "#slideshow-modal" }) %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def populate_thumbnail_slot
class: 'thumbnail thumbnail-placeholder'
)
end

thumbnail(thumbnail_content)
with_thumbnail(thumbnail_content)
end

def presenter
Expand Down
6 changes: 3 additions & 3 deletions spec/components/blacklight/gallery/document_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

let(:attr) { {} }
let(:view_context) { controller.view_context }
let(:view_context) { vc_test_controller.view_context }
let(:render) do
component.render_in(view_context)
end
Expand Down Expand Up @@ -43,13 +43,13 @@
end

before do
allow(controller).to receive(:blacklight_config).and_return(blacklight_config)
allow(vc_test_controller).to receive(:blacklight_config).and_return(blacklight_config)
allow(view_context).to receive(:current_search_session).and_return(nil)
allow(view_context).to receive(:search_session).and_return({})
allow(view_context).to receive(:blacklight_config).and_return(blacklight_config)

# dumb hack to get our stubbing into the thumbnail component
allow(controller).to receive(:view_context).and_return(view_context)
allow(vc_test_controller).to receive(:view_context).and_return(view_context)
end

it 'has a thumbnail and caption' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

let(:attr) { {} }
let(:view_context) { controller.view_context }
let(:view_context) { vc_test_controller.view_context }
let(:render) do
component.render_in(view_context)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

let(:attr) { {} }
let(:view_context) { controller.view_context }
let(:view_context) { vc_test_controller.view_context }
let(:render) do
component.render_in(view_context)
end
Expand All @@ -29,8 +29,8 @@
allow(view_context).to receive(:current_search_session).and_return(nil)
allow(view_context).to receive(:search_session).and_return({})

# dumb hack to get our stubbing into the thumbnail component
allow(controller).to receive(:view_context).and_return(view_context)
# Every call to view_context returns a different object. This ensures it stays stable.
allow(vc_test_controller).to receive(:view_context).and_return(view_context)
end

let(:blacklight_config) do
Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@

RSpec.configure do |c|
c.infer_spec_type_from_file_location!
c.full_backtrace = true
c.include ViewComponent::TestHelpers, type: :component
#onfig.assets.precompile += %w(spotlight/default_thumbnail.jpg spotlight/default_browse_thumbnail.jpg)
end

0 comments on commit 03721c4

Please sign in to comment.