Skip to content

Commit

Permalink
Remove render_document_partials
Browse files Browse the repository at this point in the history
This was only used by the atom partial renderer. We can replace this with the document component
  • Loading branch information
jcoyne committed Nov 19, 2021
1 parent 6219a8b commit 2cc68bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
12 changes: 0 additions & 12 deletions app/helpers/blacklight/render_partials_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ def render_document_index documents, locals = {}
render_document_index_with_view(document_index_view_type, documents, locals)
end

##
# Return the list of partials for a given solr document
# @param [SolrDocument] doc solr document to render partials for
# @param [Array<String>] partials list of partials to render
# @param [Hash] locals local variables to pass to the render call
# @return [String]
def render_document_partials(doc, partials = [], locals = {})
safe_join(partials.map do |action_name|
render_document_partial(doc, action_name, locals)
end, "\n")
end

##
# Return the list of xml for a given solr document. Doesn't safely escape for HTML.
# @param [SolrDocument] doc solr document to render partials for
Expand Down
5 changes: 2 additions & 3 deletions app/views/catalog/_document.atom.builder
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ xml.entry do

with_format(:html) do
xml.summary "type" => "html" do
xml.text! render_document_partials(document,
blacklight_config.view_config(:atom).summary_partials,
document_counter: document_counter)
document_component = blacklight_config.view_config(:atom).summary_component
xml.text! render document_component.new(presenter: document_presenter(document), component: :div, show: true)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def default_values
atom: {
if: false, # by default, atom should not show up as an alternative view
partials: [:document],
summary_partials: [:index]
summary_component: Blacklight::DocumentComponent
},
rss: {
if: false, # by default, rss should not show up as an alternative view
Expand Down
27 changes: 17 additions & 10 deletions spec/views/catalog/index.atom.builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
RSpec.describe "catalog/index" do
let(:document_list) do
10.times.map do |i|
doc = SolrDocument.new(id: i)
allow(doc).to receive(:export_as_some_format).and_return("")
allow(doc).to receive(:to_semantic_values).and_return(author: ['xyz']) if i == 0
doc.will_export_as(:some_format, "application/some-format") if i == 1
doc
SolrDocument.new(id: i, title_tsim: "Title #{i}").tap do |doc|
allow(doc).to receive(:export_as_some_format).and_return("")
allow(doc).to receive(:to_semantic_values).and_return(author: ['xyz']) if i == 0
doc.will_export_as(:some_format, "application/some-format") if i == 1
end
end
end

Expand Down Expand Up @@ -86,15 +86,22 @@
end

it "has a summary" do
stub_template "catalog/_index.html.erb" => "partial content"
render template: 'catalog/index', formats: [:atom]
expect(rendered).to have_selector("entry > summary", text: 'partial content')
expect(rendered).to have_selector("entry > summary", text: 'Title 0')
end

context 'with a custom HTML partial' do
context 'with a custom template' do
before do
blacklight_config.view.atom.summary_partials = ['whatever']
stub_template 'catalog/_whatever_default.html.erb' => 'whatever content'
my_template = Class.new(ViewComponent::Base) do
def call
'whatever content'
end

def self.name
'TestComponent'
end
end
blacklight_config.view.atom.summary_component = my_template
end

it "has the customized summary" do
Expand Down

0 comments on commit 2cc68bd

Please sign in to comment.