mods_display 1.0.0.alpha5 → 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: ee420c061ed577ae40b3acdf90215a8261ba96d63c53c96ed9d021ab3446fd31
4
- data.tar.gz: cec3558b7a3886f25968aec482b1126e04f7f10132382cb787f5895666b37e62
3
+ metadata.gz: fca38dd10bf2fbf3ebe62b1162b82cd9c5f63c43fff47e8021ff8d0cfa2a3f62
4
+ data.tar.gz: 60f1b639ea711faf9d021534e429f8789f0bfe3d7a5be94aa9c73da765cf180b
5
5
  SHA512:
6
- metadata.gz: 6b1a7cdb7e7f48cfd746e694577ceab478564d465416beab8cb9e307e70d0018fb06b17cf72a5be768ee7fbbf3e224b55c6bdbcada67779fb524633f750d8f08
7
- data.tar.gz: 15002dc0bea304a8d933f89e0d99116b0804ddb5fd3f6f4ec104dd890406d596c3d5694d38ccb73707d4c3cb644fa29186f91e17a444635a0d2615930aac9825
6
+ metadata.gz: 6bf3145385c0d2e40b2cabe5db955a5ccb1abb3d63a6af3825c34da1e5d4cfef3d89020866dd6d3b2de71b1ed55516833c8a550cacab2899a7b496552f878878
7
+ data.tar.gz: abf9b36c1a4299c954c7851487404fa7b0f8a29cae6c48145cd9b37a0d032fffc46bd322f00cec3519df4b356bf676cbd7e085d7b8ff13fb2484a89e88114381
data/README.md CHANGED
@@ -22,69 +22,6 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install mods_display
24
24
 
25
- Include the `ModelExtension` into your model.
26
-
27
- class MyClass
28
- include ModsDisplay::ModelExtension
29
- end
30
-
31
- Configure the source of the MODS XML in your model. You can pass a string of XML to the mods_xml_source method, however it will also accept a block where you can call methods on self (so if the MODS XML string is held in MyClass#mods):
32
-
33
- class MyClass
34
- ....
35
-
36
- mods_xml_source do |model|
37
- model.mods
38
- end
39
-
40
- end
41
-
42
- Include the `ControllerExtension` into your rails controller (or another class if not using rails).
43
-
44
- class MyController
45
- include ModsDisplay::ControllerExtension
46
- end
47
-
48
- Optionally configure the mods display gem (more on configuration later).
49
-
50
- class MyController
51
- ....
52
- configure_mods_display do
53
- ....
54
- end
55
- end
56
-
57
- ## Usage
58
-
59
- Once installed, the class that included the `ControllerExtension` (`MyController`) will have the `render_mods_display` method available. This method takes one argument which is an instance of the class that included the `ModelExtension` (`MyClass`).
60
-
61
- render_mods_display(@model) # where @model.is_a?(MyClass)
62
-
63
- The basic render call will return the top-level ModsDisplay::HTML class object. Any String method (e.g. #html_safe) you call on this top-level object will be sent down to the #to_html method which will return the HTML for all the metadata in the MODS document.
64
-
65
- render_mods_display(@model).to_html
66
-
67
- You can abstract the main (first) title by calling #title on the top-level HTML method
68
-
69
- render_mods_display(@model).title
70
-
71
- When getting JUST the main (first) title out of the metadata, it will be useful to get the rest of the metadata without the main title. You can accomplish this by calling #body on the top-level HTML object.
72
-
73
- render_mods_display(@model).body
74
-
75
- ## Advanced Usage
76
-
77
- You can also access the array of ModsDisplay::Values objects for a given class directly by calling the name of the class. The class names are not always intuitive for public consumption so you may want to check the code the particular method to call.
78
-
79
- render_mods_display(@model).abstract
80
- => [#<ModsDisplay::Values @label="Abstract:", @values=["Hey. I'm an abstract."]>]
81
-
82
- Given that this semantics that we're concerned with here are more about titles and data construction rather than XML it may be required that you find something by the label. A common example of this is the imprint class. The imprint class can return other publication data that is not the imprint statement. You'll want to select (using your favorite enumerable method) the element in the array that is an imprint.
83
-
84
- imprint = render_mods_display(@model).imprint.find do |data|
85
- data.label == "Imprint:"
86
- end.values
87
-
88
25
  ## Release/Upgrade Notes
89
26
 
90
27
  #### v0.5.0
@@ -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 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..]}"
@@ -91,12 +98,31 @@ module ModsDisplay
91
98
  if match =~ email
92
99
  val.gsub!(match, "<a href='mailto:#{match}'>#{match}</a>")
93
100
  else
101
+ match = match.delete_suffix('&gt')
102
+
94
103
  val.gsub!(match, "<a href='#{match}'>#{match}</a>")
95
104
  end
96
105
  end
97
106
  end
98
107
 
99
- 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)
100
126
  end
101
127
  # rubocop:enable Layout/LineLength
102
128
  end
@@ -73,18 +73,18 @@ module ModsDisplay
73
73
  when 'license'
74
74
  license_statement(element)
75
75
  else
76
- element.text
76
+ element_text(element)
77
77
  end
78
78
  end
79
79
 
80
80
  def copyright_statement(element)
81
- element.text.gsub(/\(c\) copyright/i, '&copy;').gsub(/\(c\)/i, '&copy;')
81
+ element_text(element).gsub(/\(c\) copyright/i, '&copy;').gsub(/\(c\)/i, '&copy;')
82
82
  end
83
83
 
84
84
  def license_statement(element)
85
- matches = element.text.match(/^(?<code>.*) (?<type>.*):(?<description>.*)$/)
85
+ matches = element_text(element).match(/^(?<code>.*) (?<type>.*):(?<description>.*)$/)
86
86
 
87
- return element.text unless matches
87
+ return element_text(element) unless matches
88
88
 
89
89
  code = matches[:code].downcase
90
90
  type = matches[:type].downcase
@@ -10,9 +10,9 @@ module ModsDisplay
10
10
  next unless value.respond_to?(:cartographics)
11
11
 
12
12
  value.cartographics.each do |field|
13
- scale = field.scale.empty? ? 'Scale not given' : field.scale.text
14
- projection = field.projection.empty? ? nil : field.projection.text
15
- coordinates = field.coordinates.empty? ? nil : field.coordinates.text
13
+ scale = field.scale.empty? ? 'Scale not given' : element_text(field.scale)
14
+ projection = field.projection.empty? ? nil : element_text(field.projection)
15
+ coordinates = field.coordinates.empty? ? nil : element_text(field.coordinates)
16
16
  post_scale = if [projection,
17
17
  coordinates].compact.length.positive?
18
18
  [projection, coordinates].compact.join(' ')
@@ -16,7 +16,7 @@ module ModsDisplay
16
16
 
17
17
  return_fields << ModsDisplay::Values.new(
18
18
  label: collection_label(value),
19
- values: [value.titleInfo.text.strip]
19
+ values: [element_text(value.titleInfo)]
20
20
  )
21
21
  end
22
22
  collapse_fields(return_fields)
@@ -4,7 +4,10 @@ module ModsDisplay
4
4
  class Contact < Field
5
5
  def fields
6
6
  return_fields = contact_fields.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || I18n.t('mods_display.contact'), values: [value.text])
7
+ ModsDisplay::Values.new(
8
+ label: displayLabel(value) || I18n.t('mods_display.contact'),
9
+ values: [element_text(value)]
10
+ )
8
11
  end
9
12
  collapse_fields(return_fields)
10
13
  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
@@ -4,7 +4,7 @@ module ModsDisplay
4
4
  class Description < Field
5
5
  def fields
6
6
  return_fields = description_fields.map do |value|
7
- ModsDisplay::Values.new(label: description_label(value), values: [value.text])
7
+ ModsDisplay::Values.new(label: description_label(value), values: [element_text(value)])
8
8
  end
9
9
  collapse_fields(return_fields)
10
10
  end
@@ -8,7 +8,7 @@ module ModsDisplay
8
8
  [
9
9
  ModsDisplay::Values.new(
10
10
  label: I18n.t('mods_display.extent'),
11
- values: extent_fields.map(&:text)
11
+ values: extent_fields.map { |x| element_text(x) }
12
12
  )
13
13
  ]
14
14
  end
@@ -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: [value.text]
13
+ values: [element_text(value)],
14
+ field: self
14
15
  )
15
16
  end
16
17
  collapse_fields(return_fields)
@@ -52,5 +53,9 @@ module ModsDisplay
52
53
  ModsDisplay::Values.new(label: group.first.label, values: group.map(&:values).flatten(1))
53
54
  end
54
55
  end
56
+
57
+ def element_text(element)
58
+ element.xpath('.//text()').to_html.strip
59
+ end
55
60
  end
56
61
  end
@@ -8,7 +8,7 @@ module ModsDisplay
8
8
  [
9
9
  ModsDisplay::Values.new(
10
10
  label: I18n.t('mods_display.form'),
11
- values: form_fields.map(&:text).uniq { |x| x.downcase.gsub(/\s/, '').gsub(/[[:punct:]]/, '') }
11
+ values: form_fields.map { |x| element_text(x) }.uniq { |x| x.downcase.gsub(/\s/, '').gsub(/[[:punct:]]/, '') }
12
12
  )
13
13
  ]
14
14
  end
@@ -4,7 +4,7 @@ module ModsDisplay
4
4
  class Genre < Field
5
5
  def fields
6
6
  return_fields = @values.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || label, values: [value.text.strip.capitalize].flatten)
7
+ ModsDisplay::Values.new(label: displayLabel(value) || label, values: [element_text(value).capitalize].flatten)
8
8
  end
9
9
  collapse_fields(return_fields)
10
10
  end
@@ -4,7 +4,7 @@ module ModsDisplay
4
4
  class Identifier < Field
5
5
  def fields
6
6
  return_fields = @values.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || identifier_label(value), values: [value.text])
7
+ ModsDisplay::Values.new(label: displayLabel(value) || identifier_label(value), values: [element_text(value)])
8
8
  end
9
9
  collapse_fields(return_fields)
10
10
  end
@@ -31,7 +31,7 @@ module ModsDisplay
31
31
  other_pub_info(value).each do |pub_info|
32
32
  return_fields << ModsDisplay::Values.new(
33
33
  label: displayLabel(value) || pub_info_labels[pub_info.name.to_sym],
34
- values: [pub_info.text.strip]
34
+ values: [element_text(pub_info)]
35
35
  )
36
36
  end
37
37
 
@@ -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
 
@@ -11,7 +11,7 @@ module ModsDisplay
11
11
 
12
12
  ModsDisplay::Values.new(
13
13
  label: displayLabel(value) || displayLabel(term) || I18n.t('mods_display.language'),
14
- values: [language_codes[term.text]]
14
+ values: [language_codes[element_text(term)]]
15
15
  )
16
16
  end.flatten.compact
17
17
  end.flatten.compact
@@ -10,10 +10,10 @@ module ModsDisplay
10
10
 
11
11
  if child.name.to_sym == :url
12
12
  loc_label = displayLabel(location) || I18n.t('mods_display.location')
13
- value = "<a href='#{child.text}'>#{(displayLabel(child) || child.text).gsub(/:$/, '')}</a>"
13
+ value = "<a href='#{element_text(child)}'>#{(displayLabel(child) || element_text(child)).gsub(/:$/, '')}</a>"
14
14
  else
15
15
  loc_label = location_label(child) || displayLabel(location) || I18n.t('mods_display.location')
16
- value = child.text
16
+ value = element_text(child)
17
17
  end
18
18
  return_fields << ModsDisplay::Values.new(
19
19
  label: loc_label || displayLabel(location) || I18n.t('mods_display.location'),
@@ -6,7 +6,7 @@ module ModsDisplay
6
6
  def fields
7
7
  return_fields = @values.map do |value|
8
8
  person = if value.displayForm.length.positive?
9
- ModsDisplay::Name::Person.new(name: value.displayForm.text)
9
+ ModsDisplay::Name::Person.new(name: element_text(value.displayForm))
10
10
  elsif !name_parts(value).empty?
11
11
  ModsDisplay::Name::Person.new(name: name_parts(value))
12
12
  end
@@ -58,7 +58,7 @@ module ModsDisplay
58
58
  end
59
59
 
60
60
  def format_role(element)
61
- element.text.capitalize.sub(/[.,:;]+$/, '')
61
+ element_text(element).capitalize.sub(/[.,:;]+$/, '')
62
62
  end
63
63
 
64
64
  def role?(element)
@@ -87,7 +87,7 @@ module ModsDisplay
87
87
 
88
88
  def unqualified_name_parts(element)
89
89
  element.namePart.map do |part|
90
- part.text unless part.attributes['type']
90
+ element_text(part) unless part.attributes['type']
91
91
  end.compact
92
92
  end
93
93
 
@@ -95,7 +95,7 @@ module ModsDisplay
95
95
  element.namePart.map do |part|
96
96
  if part.attributes['type'].respond_to?(:value) &&
97
97
  part.attributes['type'].value == type
98
- part.text
98
+ element_text(part)
99
99
  end
100
100
  end.compact
101
101
  end
@@ -121,7 +121,7 @@ module ModsDisplay
121
121
  end
122
122
  end.compact
123
123
  end
124
- roles.map { |t| t.text.strip }
124
+ roles.map { |t| element_text(t) }
125
125
  end
126
126
 
127
127
  def unencoded_role_term?(element)
@@ -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
  )
@@ -37,7 +37,13 @@ module ModsDisplay
37
37
 
38
38
  def related_item_mods_object(value)
39
39
  mods = ::Stanford::Mods::Record.new.tap do |r|
40
- r.from_str("<mods xmlns=\"http://www.loc.gov/mods/v3\">#{value.children.to_xml}</mods>")
40
+ # dup'ing the value adds the appropriate namespaces, but...
41
+ munged_node = value.dup.tap do |x|
42
+ # ... the mods gem also expects the root of the document to have the root tag <mods>
43
+ x.name = 'mods'
44
+ end
45
+
46
+ r.from_nk_node(munged_node)
41
47
  end
42
48
  related_item = ModsDisplay::HTML.new(mods)
43
49
 
@@ -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: [value.text])
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
@@ -9,13 +9,11 @@ module ModsDisplay
9
9
  next if related_item_is_a_collection?(value)
10
10
  next if render_nested_related_item?(value)
11
11
 
12
- if related_item_is_a_location?(value)
13
- process_location value
14
- elsif related_item_is_a_reference?(value)
15
- process_reference value
16
- else
17
- process_related_item(value)
18
- end
12
+ text = related_item_value(value)
13
+
14
+ next if text.nil? || text.empty?
15
+
16
+ ModsDisplay::Values.new(label: related_item_label(value), values: [text])
19
17
  end.compact
20
18
  collapse_fields(return_fields)
21
19
  end
@@ -23,28 +21,32 @@ module ModsDisplay
23
21
  private
24
22
 
25
23
  def delimiter
26
- '<br />'
27
- end
28
-
29
- def process_location(item)
30
- ModsDisplay::Values.new(label: related_item_label(item), values: [item.location.text.strip])
24
+ '<br />'.html_safe
31
25
  end
32
26
 
33
- def process_reference(item)
34
- ModsDisplay::Values.new(label: related_item_label(item), values: [reference_title(item)])
35
- end
27
+ def related_item_value(item)
28
+ if related_item_is_a_location?(item)
29
+ element_text(item.location)
30
+ elsif related_item_is_a_reference?(item)
31
+ reference_title(item)
32
+ elsif item.titleInfo.any?
33
+ title = element_text(item.titleInfo)
34
+ location = nil
35
+ location = element_text(item.location.url) if item.location.length.positive? &&
36
+ item.location.url.length.positive?
36
37
 
37
- def process_related_item(item)
38
- return unless item.titleInfo.length.positive?
38
+ return if title.empty?
39
39
 
40
- title = item.titleInfo.text.strip
41
- return_text = title
42
- location = nil
43
- location = item.location.url.text if item.location.length.positive? &&
44
- item.location.url.length.positive?
45
- return_text = "<a href='#{location}'>#{title}</a>" if location && !title.empty?
40
+ if location
41
+ "<a href='#{location}'>#{title}</a>".html_safe
42
+ else
43
+ title
44
+ end
45
+ elsif item.note.any?
46
+ citation = item.note.find { |note| note['type'] == 'preferred citation' }
46
47
 
47
- ModsDisplay::Values.new(label: related_item_label(item), values: [return_text]) unless return_text.empty?
48
+ element_text(citation) if citation
49
+ end
48
50
  end
49
51
 
50
52
  def reference_title(item)
@@ -4,7 +4,7 @@ module ModsDisplay
4
4
  class ResourceType < Field
5
5
  def fields
6
6
  return_fields = @values.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || label, values: [value.text.strip])
7
+ ModsDisplay::Values.new(label: displayLabel(value) || label, values: [element_text(value)])
8
8
  end
9
9
  collapse_fields(return_fields)
10
10
  end
@@ -12,10 +12,10 @@ module ModsDisplay
12
12
  if respond_to?(:"process_#{child.name}")
13
13
  method_send = send(:"process_#{child.name}", child)
14
14
  return_text << method_send unless method_send.to_s.empty?
15
- elsif child.text.include?('--')
16
- return_text << child.text.split('--').map(&:strip)
15
+ elsif element_text(child).include?('--')
16
+ return_text << element_text(child).split('--').map(&:strip)
17
17
  else
18
- return_text << child.text unless child.text.empty?
18
+ return_text << element_text(child) unless element_text(child).empty?
19
19
  end
20
20
  end
21
21
  return_values << return_text.flatten unless return_text.empty?
@@ -54,10 +54,10 @@ module ModsDisplay
54
54
  def values_from_subjects(element)
55
55
  return_values = []
56
56
  selected_subjects(element).each do |child|
57
- return_values << if child.text.include?('--')
58
- child.text.split('--').map(&:strip)
57
+ return_values << if element_text(child).include?('--')
58
+ element_text(child).split('--').map(&:strip)
59
59
  else
60
- child.text.strip
60
+ element_text(child)
61
61
  end
62
62
  end
63
63
  return_values
@@ -16,7 +16,7 @@ module ModsDisplay
16
16
  private
17
17
 
18
18
  def delimiter
19
- '<br />'
19
+ '<br />'.html_safe
20
20
  end
21
21
 
22
22
  def assemble_title(element)
@@ -24,7 +24,7 @@ module ModsDisplay
24
24
  previous_element = nil
25
25
 
26
26
  element.children.select { |value| title_parts.include? value.name }.each do |value|
27
- str = value.text.strip
27
+ str = element_text(value)
28
28
  next if str.empty?
29
29
 
30
30
  delimiter = if title.empty? || title.end_with?(' ')
@@ -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.0.0.alpha5'
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.0.0.alpha5
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-02-02 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
@@ -241,11 +241,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  requirements:
244
- - - ">"
244
+ - - ">="
245
245
  - !ruby/object:Gem::Version
246
- version: 1.3.1
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