mods_display 0.5.0 → 0.5.1

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
  SHA1:
3
- metadata.gz: d059d0bb717d798e323ae91d62ac65420e0b7e34
4
- data.tar.gz: bea28312f2984465139f312e585a315ec8de992f
3
+ metadata.gz: 53261106f9194d4a55bfa879bed5de2456ec8cda
4
+ data.tar.gz: a337bd0562de9d50a6361f571bdc87ff48809b38
5
5
  SHA512:
6
- metadata.gz: a7f53d54b8fbbd9dee47ccbee7120e63725e63057602da3a3cd50f569fc1d3335ed38a326d0ae072a25457f207d4ccc7722aa79a28dab3f442b2bf78f81ea35a
7
- data.tar.gz: 306dee0b66098f941dcfbb8c8f8138b001cf4f34b06b398b73a118c9f785b73c9ebab33f9e7b0233aa7cb6d8122034a0bc77f87ba355d5bc29fa45046ba6dca6
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
- return_fields = @values.map do |value|
11
- next if related_item_is_a_collection?(value)
12
- next unless render_nested_related_item?(value)
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
- related_item_mods_object(value)
15
- end.compact
16
- collapse_fields(return_fields)
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 nil if fields.empty? || @config.ignore?
21
- output = ''
22
- fields.each do |field|
23
- next unless field.values.any? { |f| f && !f.empty? }
24
- output << "<dt#{label_class} #{sanitized_field_title(field.label)}>#{field.label}</dt>"
25
- output << "<dd#{value_class}>"
26
- output << '<ul class="mods_display_nested_related_items">'
27
- output << field.values.map do |val|
28
- "<li class='mods_display_nested_related_item open'>#{link_urls_and_email(val.to_s)}</li>"
29
- end.join
30
- output << '</ul>'
31
- output << '</dd>'
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ModsDisplay
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -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
- context 'when an element that should be nested' do
35
- let(:mods) { multi_constituent_fixture }
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.0
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-28 00:00:00.000000000 Z
11
+ date: 2017-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stanford-mods