mods_display 1.0.0.alpha4 → 1.0.0.alpha5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +42 -0
- data/.rubocop_todo.yml +72 -401
- data/Gemfile +4 -1
- data/Rakefile +8 -6
- data/app/components/mods_display/field_component.rb +2 -0
- data/app/components/mods_display/list_field_component.rb +2 -0
- data/app/components/mods_display/record_component.rb +2 -0
- data/app/helpers/mods_display/record_helper.rb +4 -7
- data/app/models/mods_display/record.rb +2 -1
- data/config.ru +2 -2
- data/lib/mods_display/country_codes.rb +2 -1
- data/lib/mods_display/fields/abstract.rb +2 -0
- data/lib/mods_display/fields/access_condition.rb +7 -4
- data/lib/mods_display/fields/audience.rb +2 -0
- data/lib/mods_display/fields/cartographics.rb +8 -1
- data/lib/mods_display/fields/collection.rb +6 -2
- data/lib/mods_display/fields/contact.rb +2 -0
- data/lib/mods_display/fields/contents.rb +2 -0
- data/lib/mods_display/fields/description.rb +3 -2
- data/lib/mods_display/fields/extent.rb +3 -0
- data/lib/mods_display/fields/field.rb +6 -9
- data/lib/mods_display/fields/form.rb +3 -0
- data/lib/mods_display/fields/genre.rb +2 -0
- data/lib/mods_display/fields/geo.rb +5 -2
- data/lib/mods_display/fields/identifier.rb +20 -17
- data/lib/mods_display/fields/imprint.rb +168 -217
- data/lib/mods_display/fields/language.rb +5 -1
- data/lib/mods_display/fields/location.rb +4 -1
- data/lib/mods_display/fields/name.rb +35 -19
- data/lib/mods_display/fields/nested_related_item.rb +12 -2
- data/lib/mods_display/fields/note.rb +9 -7
- data/lib/mods_display/fields/related_item.rb +12 -9
- data/lib/mods_display/fields/resource_type.rb +2 -0
- data/lib/mods_display/fields/sub_title.rb +2 -0
- data/lib/mods_display/fields/subject.rb +17 -50
- data/lib/mods_display/fields/title.rb +37 -26
- data/lib/mods_display/fields/values.rb +2 -0
- data/lib/mods_display/html.rb +4 -3
- data/lib/mods_display/related_item_concerns.rb +4 -2
- data/lib/mods_display/relator_codes.rb +2 -0
- data/lib/mods_display/version.rb +3 -1
- data/lib/mods_display.rb +5 -3
- data/mods_display.gemspec +1 -1
- metadata +12 -6
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
##
|
3
5
|
# This class will hopefully take over for related item support more broadly.
|
@@ -21,7 +23,12 @@ module ModsDisplay
|
|
21
23
|
def to_html(view_context = ApplicationController.renderer)
|
22
24
|
helpers = view_context.respond_to?(:simple_format) ? view_context : ApplicationController.new.view_context
|
23
25
|
|
24
|
-
component = ModsDisplay::ListFieldComponent.with_collection(
|
26
|
+
component = ModsDisplay::ListFieldComponent.with_collection(
|
27
|
+
fields,
|
28
|
+
value_transformer: ->(value) { helpers.link_urls_and_email(value.to_s) },
|
29
|
+
list_html_attributes: { class: 'mods_display_nested_related_items' },
|
30
|
+
list_item_html_attributes: { class: 'mods_display_nested_related_item open' }
|
31
|
+
)
|
25
32
|
|
26
33
|
view_context.render component, layout: false
|
27
34
|
end
|
@@ -29,7 +36,9 @@ module ModsDisplay
|
|
29
36
|
private
|
30
37
|
|
31
38
|
def related_item_mods_object(value)
|
32
|
-
mods = ::Stanford::Mods::Record.new.tap
|
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>")
|
41
|
+
end
|
33
42
|
related_item = ModsDisplay::HTML.new(mods)
|
34
43
|
|
35
44
|
ModsDisplay::Values.new(
|
@@ -42,6 +51,7 @@ module ModsDisplay
|
|
42
51
|
body = related_item.body
|
43
52
|
|
44
53
|
return if body == '<dl></dl>'
|
54
|
+
|
45
55
|
body
|
46
56
|
end
|
47
57
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class Note < Field
|
3
5
|
def fields
|
@@ -25,20 +27,20 @@ module ModsDisplay
|
|
25
27
|
if element.attributes['type'].respond_to?(:value)
|
26
28
|
return note_labels[element.attributes['type'].value] || "#{element.attributes['type'].value.capitalize}:"
|
27
29
|
end
|
30
|
+
|
28
31
|
I18n.t('mods_display.note')
|
29
32
|
end
|
30
33
|
|
31
34
|
def note_labels
|
32
35
|
{ 'statement of responsibility' => I18n.t('mods_display.statement_of_responsibility'),
|
33
36
|
'date/sequential designation' => I18n.t('mods_display.date_sequential_designation'),
|
34
|
-
'publications'
|
35
|
-
'references'
|
36
|
-
'bibliography'
|
37
|
-
'preferred citation'
|
38
|
-
'biographical/historical'
|
37
|
+
'publications' => I18n.t('mods_display.publications'),
|
38
|
+
'references' => I18n.t('mods_display.references'),
|
39
|
+
'bibliography' => I18n.t('mods_display.bibliography'),
|
40
|
+
'preferred citation' => I18n.t('mods_display.preferred_citation'),
|
41
|
+
'biographical/historical' => I18n.t('mods_display.biographical_historical'),
|
39
42
|
'creation/production credits' => I18n.t('mods_display.creation_production_credits'),
|
40
|
-
'citation/reference'
|
41
|
-
}
|
43
|
+
'citation/reference' => I18n.t('mods_display.citation_reference') }
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class RelatedItem < Field
|
3
5
|
include ModsDisplay::RelatedItemConcerns
|
@@ -6,10 +8,10 @@ module ModsDisplay
|
|
6
8
|
return_fields = @values.map do |value|
|
7
9
|
next if related_item_is_a_collection?(value)
|
8
10
|
next if render_nested_related_item?(value)
|
9
|
-
|
10
|
-
|
11
|
+
|
12
|
+
if related_item_is_a_location?(value)
|
11
13
|
process_location value
|
12
|
-
|
14
|
+
elsif related_item_is_a_reference?(value)
|
13
15
|
process_reference value
|
14
16
|
else
|
15
17
|
process_related_item(value)
|
@@ -33,12 +35,13 @@ module ModsDisplay
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def process_related_item(item)
|
36
|
-
return unless item.titleInfo.length
|
38
|
+
return unless item.titleInfo.length.positive?
|
39
|
+
|
37
40
|
title = item.titleInfo.text.strip
|
38
41
|
return_text = title
|
39
42
|
location = nil
|
40
|
-
location = item.location.url.text if item.location.length
|
41
|
-
item.location.url.length
|
43
|
+
location = item.location.url.text if item.location.length.positive? &&
|
44
|
+
item.location.url.length.positive?
|
42
45
|
return_text = "<a href='#{location}'>#{title}</a>" if location && !title.empty?
|
43
46
|
|
44
47
|
ModsDisplay::Values.new(label: related_item_label(item), values: [return_text]) unless return_text.empty?
|
@@ -54,8 +57,8 @@ module ModsDisplay
|
|
54
57
|
def related_item_is_a_location?(item)
|
55
58
|
!related_item_is_a_collection?(item) &&
|
56
59
|
!related_item_is_a_reference?(item) &&
|
57
|
-
item.location.length
|
58
|
-
item.titleInfo.
|
60
|
+
item.location.length.positive? &&
|
61
|
+
item.titleInfo.empty?
|
59
62
|
end
|
60
63
|
|
61
64
|
def related_item_is_a_reference?(item)
|
@@ -66,7 +69,7 @@ module ModsDisplay
|
|
66
69
|
|
67
70
|
def related_item_label(item)
|
68
71
|
if displayLabel(item)
|
69
|
-
|
72
|
+
displayLabel(item)
|
70
73
|
else
|
71
74
|
case
|
72
75
|
when related_item_is_a_location?(item)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class Subject < Field
|
3
5
|
def fields
|
@@ -7,23 +9,19 @@ module ModsDisplay
|
|
7
9
|
label = displayLabel(value) || I18n.t('mods_display.subject')
|
8
10
|
return_text = []
|
9
11
|
selected_subjects(value).each do |child|
|
10
|
-
if
|
12
|
+
if respond_to?(:"process_#{child.name}")
|
11
13
|
method_send = send(:"process_#{child.name}", child)
|
12
14
|
return_text << method_send unless method_send.to_s.empty?
|
15
|
+
elsif child.text.include?('--')
|
16
|
+
return_text << child.text.split('--').map(&:strip)
|
13
17
|
else
|
14
|
-
|
15
|
-
return_text << child.text.split('--').map(&:strip)
|
16
|
-
else
|
17
|
-
return_text << child.text unless child.text.empty?
|
18
|
-
end
|
18
|
+
return_text << child.text unless child.text.empty?
|
19
19
|
end
|
20
20
|
end
|
21
21
|
return_values << return_text.flatten unless return_text.empty?
|
22
|
-
unless return_values.empty?
|
23
|
-
return_fields << ModsDisplay::Values.new(label: label, values: return_values)
|
24
|
-
end
|
22
|
+
return_fields << ModsDisplay::Values.new(label: label, values: return_values) unless return_values.empty?
|
25
23
|
end
|
26
|
-
|
24
|
+
collapse_fields return_fields
|
27
25
|
end
|
28
26
|
|
29
27
|
# Would really like to clean this up, but it works and is tested for now.
|
@@ -44,7 +42,7 @@ module ModsDisplay
|
|
44
42
|
def process_name(element)
|
45
43
|
name = ModsDisplay::Name.new([element]).fields.first
|
46
44
|
|
47
|
-
name
|
45
|
+
name&.values&.first
|
48
46
|
end
|
49
47
|
|
50
48
|
private
|
@@ -56,54 +54,23 @@ module ModsDisplay
|
|
56
54
|
def values_from_subjects(element)
|
57
55
|
return_values = []
|
58
56
|
selected_subjects(element).each do |child|
|
59
|
-
if child.text.include?('--')
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
return_values << if child.text.include?('--')
|
58
|
+
child.text.split('--').map(&:strip)
|
59
|
+
else
|
60
|
+
child.text.strip
|
61
|
+
end
|
64
62
|
end
|
65
63
|
return_values
|
66
64
|
end
|
67
65
|
|
68
66
|
def selected_subjects(element = @value)
|
69
|
-
element.children.
|
70
|
-
|
67
|
+
element.children.reject do |child|
|
68
|
+
omit_elements.include?(child.name.to_sym)
|
71
69
|
end
|
72
70
|
end
|
73
71
|
|
74
72
|
def omit_elements
|
75
|
-
[
|
76
|
-
end
|
77
|
-
|
78
|
-
# Providing subject specific collapsing method so we can
|
79
|
-
# collapse the labels w/o flattening all the subject fields.
|
80
|
-
def collapse_subjects(display_fields)
|
81
|
-
return_values = []
|
82
|
-
current_label = nil
|
83
|
-
prev_label = nil
|
84
|
-
buffer = []
|
85
|
-
display_fields.each_with_index do |field, index|
|
86
|
-
current_label = field.label
|
87
|
-
current_values = field.values
|
88
|
-
if display_fields.length == 1
|
89
|
-
return_values << ModsDisplay::Values.new(label: current_label, values: current_values)
|
90
|
-
elsif index == (display_fields.length - 1)
|
91
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
92
|
-
if current_label != prev_label
|
93
|
-
return_values << ModsDisplay::Values.new(label: prev_label, values: [buffer.flatten(1)])
|
94
|
-
return_values << ModsDisplay::Values.new(label: current_label, values: current_values)
|
95
|
-
else
|
96
|
-
buffer.concat(current_values)
|
97
|
-
return_values << ModsDisplay::Values.new(label: current_label, values: buffer.flatten(0))
|
98
|
-
end
|
99
|
-
elsif prev_label && (current_label != prev_label)
|
100
|
-
return_values << ModsDisplay::Values.new(label: prev_label, values: buffer.flatten(0))
|
101
|
-
buffer = []
|
102
|
-
end
|
103
|
-
buffer.concat(current_values)
|
104
|
-
prev_label = current_label
|
105
|
-
end
|
106
|
-
return_values
|
73
|
+
%i[cartographics geographicCode text]
|
107
74
|
end
|
108
75
|
end
|
109
76
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class Title < Field
|
3
5
|
def fields
|
4
6
|
return_values = []
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
)
|
11
|
-
end
|
7
|
+
@values&.each do |value|
|
8
|
+
return_values << ModsDisplay::Values.new(
|
9
|
+
label: displayLabel(value) || title_label(value),
|
10
|
+
values: [assemble_title(value)]
|
11
|
+
)
|
12
12
|
end
|
13
13
|
collapse_fields(return_values)
|
14
14
|
end
|
@@ -20,8 +20,6 @@ module ModsDisplay
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def assemble_title(element)
|
23
|
-
return displayForm(element) if displayForm(element)
|
24
|
-
|
25
23
|
title = ''
|
26
24
|
previous_element = nil
|
27
25
|
|
@@ -29,20 +27,21 @@ module ModsDisplay
|
|
29
27
|
str = value.text.strip
|
30
28
|
next if str.empty?
|
31
29
|
|
32
|
-
delimiter =
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
30
|
+
delimiter = if title.empty? || title.end_with?(' ')
|
31
|
+
nil
|
32
|
+
elsif previous_element&.name == 'nonSort' && title.end_with?('-', '\'')
|
33
|
+
nil
|
34
|
+
elsif title.end_with?('.', ',', ':', ';')
|
35
|
+
' '
|
36
|
+
elsif value.name == 'subTitle'
|
37
|
+
' : '
|
38
|
+
elsif value.name == 'partName' && previous_element.name == 'partNumber'
|
39
|
+
', '
|
40
|
+
elsif value.name == 'partNumber' || value.name == 'partName'
|
41
|
+
'. '
|
42
|
+
else
|
43
|
+
' '
|
44
|
+
end
|
46
45
|
|
47
46
|
title += delimiter if delimiter
|
48
47
|
title += str
|
@@ -50,7 +49,18 @@ module ModsDisplay
|
|
50
49
|
previous_element = value
|
51
50
|
end
|
52
51
|
|
53
|
-
|
52
|
+
if element['type'] == 'uniform' && element['nameTitleGroup'].present?
|
53
|
+
[uniform_title_name_part(element), title].compact.join('. ')
|
54
|
+
else
|
55
|
+
title
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def uniform_title_name_part(element)
|
60
|
+
names = element.xpath("//m:name[@nameTitleGroup=\"#{element['nameTitleGroup']}\"]", **Mods::Record::NS_HASH)
|
61
|
+
names = element.xpath("//name[@nameTitleGroup=\"#{element['nameTitleGroup']}\"]") if names.empty?
|
62
|
+
|
63
|
+
ModsDisplay::Name.new(names).fields.first&.values&.first&.to_s
|
54
64
|
end
|
55
65
|
|
56
66
|
def title_parts
|
@@ -62,14 +72,15 @@ module ModsDisplay
|
|
62
72
|
title_labels.key?(element.attributes['type'].value)
|
63
73
|
return title_labels[element.attributes['type'].value]
|
64
74
|
end
|
75
|
+
|
65
76
|
I18n.t('mods_display.title')
|
66
77
|
end
|
67
78
|
|
68
79
|
def title_labels
|
69
80
|
{ 'abbreviated' => I18n.t('mods_display.abbreviated_title'),
|
70
|
-
'translated'
|
81
|
+
'translated' => I18n.t('mods_display.translated_title'),
|
71
82
|
'alternative' => I18n.t('mods_display.alternative_title'),
|
72
|
-
'uniform'
|
83
|
+
'uniform' => I18n.t('mods_display.uniform_title') }
|
73
84
|
end
|
74
85
|
end
|
75
86
|
end
|
data/lib/mods_display/html.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class HTML
|
3
5
|
MODS_DISPLAY_FIELD_MAPPING = {
|
@@ -33,9 +35,8 @@ module ModsDisplay
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def title
|
36
|
-
unless mods_field(:title).fields.empty?
|
37
|
-
|
38
|
-
end
|
38
|
+
return mods_field(:title).fields.first.values unless mods_field(:title).fields.empty?
|
39
|
+
|
39
40
|
''
|
40
41
|
end
|
41
42
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
module RelatedItemConcerns
|
3
5
|
private
|
@@ -16,12 +18,12 @@ module ModsDisplay
|
|
16
18
|
|
17
19
|
def related_item_is_a_constituent?(item)
|
18
20
|
item.attributes['type'].respond_to?(:value) &&
|
19
|
-
|
21
|
+
item.attributes['type'].value == 'constituent'
|
20
22
|
end
|
21
23
|
|
22
24
|
def related_item_is_host?(item)
|
23
25
|
item.attributes['type'].respond_to?(:value) &&
|
24
|
-
|
26
|
+
item.attributes['type'].value == 'host'
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/mods_display/version.rb
CHANGED
data/lib/mods_display.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mods_display/version'
|
2
4
|
require 'mods_display/html'
|
3
5
|
require 'mods_display/country_codes'
|
@@ -34,14 +36,14 @@ require 'stanford-mods'
|
|
34
36
|
|
35
37
|
require 'i18n'
|
36
38
|
require 'i18n/backend/fallbacks'
|
37
|
-
I18n::Backend::Simple.
|
38
|
-
I18n.load_path += Dir["#{File.expand_path('
|
39
|
+
I18n::Backend::Simple.include I18n::Backend::Fallbacks
|
40
|
+
I18n.load_path += Dir["#{File.expand_path('..', __dir__)}/config/locales/*.yml"]
|
39
41
|
I18n.backend.load_translations
|
40
42
|
|
41
43
|
begin
|
42
44
|
require 'rails'
|
43
45
|
rescue LoadError
|
44
|
-
#do nothing
|
46
|
+
# do nothing
|
45
47
|
end
|
46
48
|
|
47
49
|
require 'mods_display/engine' if defined?(Rails)
|
data/mods_display.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.executables = gem.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
22
22
|
gem.require_paths = ["lib"]
|
23
23
|
|
24
|
-
gem.add_dependency 'stanford-mods', '
|
24
|
+
gem.add_dependency 'stanford-mods', '>= 3.0.0.alpha1', '< 4'
|
25
25
|
gem.add_dependency 'i18n'
|
26
26
|
gem.add_dependency 'view_component'
|
27
27
|
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mods_display
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.alpha5
|
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-
|
11
|
+
date: 2022-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stanford-mods
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0.alpha1
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '4'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0.alpha1
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '4'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: i18n
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|