Skip to content

Commit

Permalink
Merge pull request #397 from trln/imprint-remove-html-safe
Browse files Browse the repository at this point in the history
Imprint remove html safe
  • Loading branch information
kazymovae authored Mar 10, 2023
2 parents 8c5c544 + 636d3e1 commit ead0cd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.4
2.2.5
29 changes: 23 additions & 6 deletions lib/trln_argon/solr_document/imprint.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
module TrlnArgon
module SolrDocument
# In addition to marking the imprint (resulting) value as
# "html_safe", work is done to ensure < and > are preserved...
#
# ...because some catalogers are adding &lt; and &gt;
# in subfield $3.
#
# DEVELOPERS' NOTE
# We are aware that we're possibly violating the spirit
# of the "Single Responsibily Principle" with this
# approach, but it was either here, or taking a
# deep-dive at parsing through FieldPresenters and/or
# ShowPresenters to determine if we are displaying
# the "imprint" field.
module Imprint
def imprint_main_for_header_display
imprint_main.reverse.map do |imprint|
Expand All @@ -8,8 +21,8 @@ def imprint_main_for_header_display
end

def imprint_multiple_for_display
imprint_multiple.map { |imprint| imprint_entry(imprint) }
.concat(imprint_main.map { |imprint| imprint_entry(imprint) })
imprint_multiple.map { |imprint| imprint_entry(imprint, escape_label: true) }
.concat(imprint_main.map { |imprint| imprint_entry(imprint, escape_label: true) })
.uniq
.join('<br />').html_safe
end
Expand All @@ -34,9 +47,9 @@ def imprint_multiple

private

def imprint_entry(imprint)
def imprint_entry(imprint, escape_label: false)
[imprint_type(imprint),
imprint_label(imprint),
imprint_label(imprint, escape_label: escape_label),
imprint_value(imprint)].compact.join(': ')
end

Expand All @@ -45,9 +58,13 @@ def imprint_type(imprint)
I18n.t("trln_argon.imprint_type.#{imprint[:type]}")
end

def imprint_label(imprint)
# when needed, replace < and > with their intended
# escaped &lt; and &gt; string values.
def imprint_label(imprint, escape_label: false)
return if imprint[:label].blank?
imprint[:label]
return imprint[:label] unless escape_label
imprint[:label].gsub! '<', ' &lt;'
imprint[:label].gsub '>', '&gt;'
end

def imprint_value(imprint)
Expand Down

0 comments on commit ead0cd3

Please sign in to comment.