diff --git a/app/assets/stylesheets/scss/layout.scss b/app/assets/stylesheets/scss/layout.scss index 31e272b3..016a75b5 100644 --- a/app/assets/stylesheets/scss/layout.scss +++ b/app/assets/stylesheets/scss/layout.scss @@ -119,4 +119,19 @@ a { color: $bright-blue; } } -/*** end Home Page ***/ \ No newline at end of file +/*** end Home Page ***/ + +/*** Remaining Authors Toggle ***/ +/* shows up on both search results and show item pages */ +a.remaining-authors-collapse { + text-transform: uppercase; + padding-left: 0.9375rem; + line-height: 2.5rem; + font-size: smaller; +} +a.remaining-authors-collapse.collapsed:after { + content: "+ Show more authors/creators"; +} +a.remaining-authors-collapse:not(.collapsed):after { + content: "+ Show fewer authors/creators"; +} \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a8150ee2..4a17f99d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,22 +1,15 @@ # frozen_string_literal: true +# rubocop:disable Rails/OutputSafety module ApplicationHelper def emory_creators_display(presenter) values = presenter.is_a?(Hash) ? presenter[:value] : presenter.solr_document['creator_ssim'] + values_html = pull_html_values(values) + first_five = values_html.first(5) + remaining_authors = values_html.drop(5) + return_array = raw(safe_join(first_five)) - safe_join( - values.map do |author| - parsed_author = parse_creator_string(author) - author_span = - if parsed_author[:orcid].present? - sanitize("#{parsed_author[:first_name]} #{parsed_author[:last_name]} #{orcid_link_for_creator(parsed_author[:orcid])} - #{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}") - else - tag.span("#{parsed_author[:first_name]} #{parsed_author[:last_name]}#{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}", itemprop: 'name') - end - - content_tag(:span, author_span, itemprop: 'creator', itemscope: '', itemtype: 'http://schema.org/Person', class: 'attribute attribute-creator') - end - ) + return_array << remaining_authors_html(remaining_authors) if remaining_authors.present? + return_array end def orcid_link_for_creator(orcid_id) @@ -53,4 +46,27 @@ def extract_orcid(parts) def valid_orcid?(id) id.to_s.match?(/^\d{4}-\d{4}-\d{4}-\d{3}[0-9X]$/) end + + def remaining_authors_html(remaining_authors) + raw( + "#{safe_join(remaining_authors)} + " + ) + end + + def pull_html_values(values) + values.map do |author| + parsed_author = parse_creator_string(author) + author_span = + if parsed_author[:orcid].present? + sanitize("#{parsed_author[:first_name]} #{parsed_author[:last_name]} #{orcid_link_for_creator(parsed_author[:orcid])} + #{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}") + else + tag.span("#{parsed_author[:first_name]} #{parsed_author[:last_name]}#{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}", itemprop: 'name') + end + + content_tag(:span, author_span, itemprop: 'creator', itemscope: '', itemtype: 'http://schema.org/Person', class: 'attribute attribute-creator') + end + end end +# rubocop:enable Rails/OutputSafety