Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Add helper method to truncate arrays; Resolves #9
Browse files Browse the repository at this point in the history
* Truncate fields that are arrays over 5 items;
* Add test for helper method;
* Use helper method on links_domains for search results.
  • Loading branch information
ruebot committed Oct 11, 2017
1 parent eece597 commit 0b42907
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/helpers/warclight_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ def url_to_link(options = {})
end
end, '')
end

def return_five(options = {})
options[:value][0, 5].join('; ') + '...'
end
end
3 changes: 1 addition & 2 deletions lib/generators/warclight/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class CatalogController < ApplicationController
config.add_index_field 'institution', label: 'Institution', link_to_facet: true
config.add_index_field 'collection_name', label: 'Collection Name', link_to_facet: true
config.add_index_field 'collection_number', label: 'Collection Number', link_to_facet: true
config.add_index_field 'links_domains', label: 'This page links to', link_to_facet: true,
separator_options: { words_connector: '; ' }
config.add_index_field 'links_domains', label: 'This page links to', helper_method: :return_five

# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
Expand Down
8 changes: 8 additions & 0 deletions spec/helpers/warclight_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@
end
end
end

describe '#return_five' do
context 'when a field has more than 5 items' do
it 'prints the first 5 items in the array, seperated by ";", and ends with "..."' do
expect(helper.return_five(value: %w[a b c d e f])).to eq('a; b; c; d; e...')
end
end
end
end

0 comments on commit 0b42907

Please sign in to comment.