mods_display 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab657c57e41e5c014b54751efb2a1e7e2a3de69449215a040446ba56e5012cc3
4
- data.tar.gz: 19b3ffeda4c16b78a66cbe644f8c1894cdce91ca1eac9902d52a89676357432b
3
+ metadata.gz: fca38dd10bf2fbf3ebe62b1162b82cd9c5f63c43fff47e8021ff8d0cfa2a3f62
4
+ data.tar.gz: 60f1b639ea711faf9d021534e429f8789f0bfe3d7a5be94aa9c73da765cf180b
5
5
  SHA512:
6
- metadata.gz: df1c227cf9f7a8dc03ff406f3e6e18f5697324216621a609bd0c8e137a8ce3fc8b7cd2e1d11bb6354d40bc8d404790c9a2d6f6512b14338f4d903c9ea3c75eeb
7
- data.tar.gz: 70063931db7fae164481f2be8d7e8ab0b155ed1231934deea4fb630092711a69c51b17ab499575f29ac02ee6af9036a10efbf9e2d1c8dded8bd0de11cd17d3e4
6
+ metadata.gz: 6bf3145385c0d2e40b2cabe5db955a5ccb1abb3d63a6af3825c34da1e5d4cfef3d89020866dd6d3b2de71b1ed55516833c8a550cacab2899a7b496552f878878
7
+ data.tar.gz: abf9b36c1a4299c954c7851487404fa7b0f8a29cae6c48145cd9b37a0d032fffc46bd322f00cec3519df4b356bf676cbd7e085d7b8ff13fb2484a89e88114381
@@ -22,7 +22,7 @@ module ModsDisplay
22
22
  if @value_transformer
23
23
  @value_transformer.call(value)
24
24
  else
25
- helpers.link_urls_and_email(value)
25
+ helpers.format_mods_html(value, field: @field)
26
26
  end
27
27
  end
28
28
  end
@@ -69,12 +69,19 @@ module ModsDisplay
69
69
  link
70
70
  end
71
71
 
72
- # rubocop:disable Layout/LineLength
73
- # @private, but used in PURL currently
74
- def link_urls_and_email(val, tags: %w[a dl dd dt i b em strong cite br])
72
+ def format_mods_html(val, tags: %w[a dl dd dt i b em strong cite br], field: nil)
75
73
  val = val.gsub(%r{<[^/> ]+}) do |possible_tag|
76
74
  # Allow potentially valid HTML tags through to the sanitizer step, and HTML escape the rest
77
- if tags.include? possible_tag[1..]
75
+ if tags.include?(possible_tag[1..])
76
+ possible_tag
77
+ else
78
+ "&lt;#{possible_tag[1..]}"
79
+ end
80
+ end
81
+
82
+ val = val.gsub(%r{</[^> ]+}) do |possible_tag|
83
+ # Allow potentially valid HTML tags through to the sanitizer step, and HTML escape the rest
84
+ if tags.include?(possible_tag[2..])
78
85
  possible_tag
79
86
  else
80
87
  "&lt;#{possible_tag[1..]}"
@@ -98,7 +105,24 @@ module ModsDisplay
98
105
  end
99
106
  end
100
107
 
101
- sanitize val, tags: tags, attributes: %w[href]
108
+ formatted_val = sanitize val, tags: tags, attributes: %w[href]
109
+
110
+ # Martin Wong data has significant linebreaks in abstracts and notes that we want
111
+ # to preserve and display in HTML.
112
+ #
113
+ # See https://github.com/sul-dlss/mods_display/issues/78
114
+ simple_formatted_fields = [ModsDisplay::Abstract, ModsDisplay::Contents, ModsDisplay::Note]
115
+ if simple_formatted_fields.any? { |klass| field&.field.is_a? klass } && formatted_val.include?("\n")
116
+ simple_format(formatted_val, {}, sanitize: false)
117
+ else
118
+ formatted_val
119
+ end
120
+ end
121
+
122
+ # rubocop:disable Layout/LineLength
123
+ # @private, but used in PURL currently
124
+ def link_urls_and_email(val, tags: %w[a dl dd dt i b em strong cite br])
125
+ format_mods_html(val, tags: tags)
102
126
  end
103
127
  # rubocop:enable Layout/LineLength
104
128
  end
@@ -4,7 +4,7 @@ module ModsDisplay
4
4
  class Contents < Field
5
5
  def to_html(view_context = ApplicationController.renderer)
6
6
  f = fields.map do |field|
7
- ModsDisplay::Values.new(label: field.label, values: [field.values.join("\n\n")])
7
+ ModsDisplay::Values.new(label: field.label, values: [field.values.join("\n\n")], field: self)
8
8
  end
9
9
 
10
10
  helpers = view_context.respond_to?(:simple_format) ? view_context : ApplicationController.new.view_context
@@ -10,7 +10,8 @@ module ModsDisplay
10
10
  return_fields = @values.map do |value|
11
11
  ModsDisplay::Values.new(
12
12
  label: displayLabel(value) || label,
13
- values: [element_text(value)]
13
+ values: [element_text(value)],
14
+ field: self
14
15
  )
15
16
  end
16
17
  collapse_fields(return_fields)
@@ -67,7 +67,7 @@ module ModsDisplay
67
67
  end
68
68
 
69
69
  # Element text reduced to digits and hyphen. Captures date ranges and
70
- # negative (B.C.) dates. Used for comparison/deduping.
70
+ # negative (BCE) dates. Used for comparison/deduping.
71
71
  def base_value
72
72
  if text =~ /^\[?1\d{3}-\d{2}\??\]?$/
73
73
  return text.sub(/(\d{2})(\d{2})-(\d{2})/, '\1\2-\1\3')
@@ -93,10 +93,10 @@ module ModsDisplay
93
93
  when :year
94
94
  year = date.year
95
95
  if year < 1
96
- "#{year.abs + 1} B.C."
97
- # Any dates before the year 1000 are explicitly marked A.D.
96
+ "#{year.abs + 1} BCE"
97
+ # Any dates before the year 1000 are explicitly marked CE
98
98
  elsif year > 1 && year < 1000
99
- "#{year} A.D."
99
+ "#{year} CE"
100
100
  else
101
101
  year.to_s
102
102
  end
@@ -109,7 +109,7 @@ module ModsDisplay
109
109
  end
110
110
  end
111
111
 
112
- # Decoded date with "B.C." or "A.D." and qualifier markers. See (outdated):
112
+ # Decoded date with "BCE" or "CE" and qualifier markers. See (outdated):
113
113
  # https://consul.stanford.edu/display/chimera/MODS+display+rules#MODSdisplayrules-3b.%3CoriginInfo%3E
114
114
  def qualified_value
115
115
  date = decoded_value
@@ -143,7 +143,7 @@ module ModsDisplay
143
143
  @start&.encoding || @stop&.encoding
144
144
  end
145
145
 
146
- # Decoded dates with "B.C." or "A.D." and qualifier markers applied to
146
+ # Decoded dates with "BCE" or "CE" and qualifier markers applied to
147
147
  # the entire range, or individually if dates differ.
148
148
  def qualified_value
149
149
  if @start&.qualifier == @stop&.qualifier
@@ -192,7 +192,7 @@ module ModsDisplay
192
192
  .map(&:base_values).flatten
193
193
  dates = dates.reject { |date| range_base_values.include?(date.base_value) }
194
194
 
195
- # output formatted dates with qualifiers, A.D./B.C., etc.
195
+ # output formatted dates with qualifiers, CE/BCE, etc.
196
196
  dates.map(&:qualified_value)
197
197
  end
198
198
 
@@ -25,7 +25,7 @@ module ModsDisplay
25
25
 
26
26
  component = ModsDisplay::ListFieldComponent.with_collection(
27
27
  fields,
28
- value_transformer: ->(value) { helpers.link_urls_and_email(value.to_s) },
28
+ value_transformer: ->(value) { helpers.format_mods_html(value.to_s) },
29
29
  list_html_attributes: { class: 'mods_display_nested_related_items' },
30
30
  list_item_html_attributes: { class: 'mods_display_nested_related_item open' }
31
31
  )
@@ -4,7 +4,7 @@ module ModsDisplay
4
4
  class Note < Field
5
5
  def fields
6
6
  return_fields = note_fields.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || note_label(value), values: [element_text(value)])
7
+ ModsDisplay::Values.new(label: displayLabel(value) || note_label(value), values: [element_text(value)], field: self)
8
8
  end
9
9
  collapse_fields(return_fields)
10
10
  end
@@ -12,7 +12,7 @@ module ModsDisplay
12
12
  private
13
13
 
14
14
  def delimiter
15
- '<br />'
15
+ '<br />'.html_safe
16
16
  end
17
17
 
18
18
  def note_fields
@@ -2,11 +2,12 @@
2
2
 
3
3
  module ModsDisplay
4
4
  class Values
5
- attr_accessor :label, :values
5
+ attr_accessor :label, :values, :field
6
6
 
7
- def initialize(label: nil, values: [])
7
+ def initialize(label: nil, values: [], field: nil)
8
8
  @label = label
9
9
  @values = values
10
+ @field = field
10
11
  end
11
12
  end
12
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ModsDisplay
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jessie Keck
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-07 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stanford-mods
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  - !ruby/object:Gem::Version
246
246
  version: '0'
247
247
  requirements: []
248
- rubygems_version: 3.2.32
248
+ rubygems_version: 3.3.7
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: The MODS Display gem allows implementers to configure a customized display