Skip to content

Commit

Permalink
[WIP] Ensuring that the IndexPresenter label for titles is a single S…
Browse files Browse the repository at this point in the history
…tring value in the index masonry view
  • Loading branch information
jrgriffiniii committed Jun 21, 2018
1 parent 82434cd commit 9580c46
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/helpers/index_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module IndexHelper
def render_index_document(document)
field = index_presenter(document).label(document_show_link_field(document))
field = field_from document: document
span = []
if !field.is_a?(Array)
span << content_tag(:span, style: 'display: block;', dir: field.dir) do
Expand All @@ -15,4 +15,19 @@ def render_index_document(document)
end
safe_join span
end

# Ensures that only a single string is passed from the IndexPresenter
# @param current_presenter [Class]
# @param show_link_field [Symbol]
# @return [String]
def index_masonry_document_label(document)
field = field_from document: document
Array.wrap(field).first
end

private

def field_from(document:)
index_presenter(document).label(document_show_link_field(document))
end
end
1 change: 1 addition & 0 deletions app/views/catalog/_index_masonry_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= link_to_document(document, truncate(index_masonry_document_label(document), length: 89)) %>
11 changes: 11 additions & 0 deletions spec/helpers/index_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ class TestingHelper
Object.send(:remove_const, :TestingHelper)
end

describe '#index_masonry_document_label' do
let(:label) { 'title' }

before do
allow(helper).to receive(:index_presenter).and_return(index_presenter)
allow(helper).to receive(:document_show_link_field).and_return(:full_title_tesim)
allow(index_presenter).to receive(:label).and_return(label)
end

end

describe '#render_index_document' do
before do
allow(helper).to receive(:index_presenter).and_return(index_presenter)
Expand Down

0 comments on commit 9580c46

Please sign in to comment.