mods_display 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53261106f9194d4a55bfa879bed5de2456ec8cda
|
4
|
+
data.tar.gz: a337bd0562de9d50a6361f571bdc87ff48809b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a41f34b9565c81f5ab3ce15c08e43bdedf5793021cef6e6f65526c13174f798288b0636ff8ce0332fbcfd5b69137caa2e3a015b6ba61e9417b62ced3d618e171
|
7
|
+
data.tar.gz: adaccbdda2e72b8eebadf19b18d1628c799efa300d63c0813dfc9112c1656eee3f583acd2309619dc1fbe97f0c90ee153e4898cab2cbf700bbb6dcc04a5a2eeb
|
@@ -7,30 +7,34 @@ module ModsDisplay
|
|
7
7
|
include ModsDisplay::RelatedItemConcerns
|
8
8
|
|
9
9
|
def fields
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
@fields ||= begin
|
11
|
+
return_fields = @values.map do |value|
|
12
|
+
next if related_item_is_a_collection?(value)
|
13
|
+
next unless render_nested_related_item?(value)
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
related_item_mods_object(value)
|
16
|
+
end.compact
|
17
|
+
collapse_fields(return_fields)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
def to_html
|
20
|
-
return
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
return if fields.empty? || @config.ignore?
|
23
|
+
@to_html ||= begin
|
24
|
+
output = ''
|
25
|
+
fields.each do |field|
|
26
|
+
next unless field.values.any? { |f| f && !f.empty? }
|
27
|
+
output << "<dt#{label_class} #{sanitized_field_title(field.label)}>#{field.label}</dt>"
|
28
|
+
output << "<dd#{value_class}>"
|
29
|
+
output << '<ul class="mods_display_nested_related_items">'
|
30
|
+
output << field.values.map do |val|
|
31
|
+
"<li class='mods_display_nested_related_item open'>#{link_urls_and_email(val.to_s)}</li>"
|
32
|
+
end.join
|
33
|
+
output << '</ul>'
|
34
|
+
output << '</dd>'
|
35
|
+
end
|
36
|
+
output
|
32
37
|
end
|
33
|
-
output
|
34
38
|
end
|
35
39
|
|
36
40
|
private
|
data/lib/mods_display/html.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module ModsDisplay
|
2
2
|
class HTML
|
3
|
-
attr_reader :title, :body
|
4
3
|
def initialize(config, xml, klass)
|
5
4
|
@config = config
|
6
5
|
@stanford_mods = xml
|
@@ -24,9 +23,7 @@ module ModsDisplay
|
|
24
23
|
body_fields[0] = :subTitle
|
25
24
|
body_fields.each do |field_key|
|
26
25
|
field = mods_field(@xml, field_key)
|
27
|
-
unless field.nil? || field.to_html.nil?
|
28
|
-
output << mods_field(@xml, field_key).to_html
|
29
|
-
end
|
26
|
+
output << field.to_html unless field.nil? || field.to_html.nil?
|
30
27
|
end
|
31
28
|
output << '</dl>'
|
32
29
|
end
|
data/lib/mods_display/version.rb
CHANGED
@@ -29,11 +29,18 @@ describe ModsDisplay::NestedRelatedItem do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '#fields' do
|
32
|
+
let(:mods) { multi_constituent_fixture }
|
32
33
|
subject(:fields) { nested_related_item.fields }
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
describe 'memoization' do
|
36
|
+
it 'only calls related_item_mods_object once per item regardless of how many times the method is called' do
|
37
|
+
expect(nested_related_item).to receive(:related_item_mods_object).exactly(2).times
|
38
|
+
|
39
|
+
5.times { nested_related_item.fields }
|
40
|
+
end
|
41
|
+
end
|
36
42
|
|
43
|
+
context 'when an element that should be nested' do
|
37
44
|
it 'has a field for each related item' do
|
38
45
|
expect(fields.length).to eq 1
|
39
46
|
end
|
@@ -59,6 +66,16 @@ describe ModsDisplay::NestedRelatedItem do
|
|
59
66
|
subject(:html) { Capybara.string(nested_related_item.to_html) }
|
60
67
|
let(:mods) { related_item_host_fixture }
|
61
68
|
|
69
|
+
describe 'memoization' do
|
70
|
+
let(:mods) { multi_constituent_fixture }
|
71
|
+
|
72
|
+
it 'only loops throug hthe fields once regardless of how many times the method is called' do
|
73
|
+
expect(nested_related_item.fields).to receive(:each).exactly(1).times.and_call_original
|
74
|
+
|
75
|
+
5.times { nested_related_item.to_html }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
62
79
|
it 'renders an unordered list with an embedded dl containing the metadata of the related item' do
|
63
80
|
within(html.first('dd')) do |dd|
|
64
81
|
expect(dd).to have_css('ul.mods_display_nested_related_items')
|
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: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jessie Keck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stanford-mods
|