mods_display 0.3.3 → 0.3.4
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 +4 -4
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +60 -0
- data/.travis.yml +2 -2
- data/Rakefile +10 -2
- data/lib/mods_display.rb +42 -42
- data/lib/mods_display/configuration.rb +69 -67
- data/lib/mods_display/configuration/access_condition.rb +17 -13
- data/lib/mods_display/configuration/base.rb +27 -24
- data/lib/mods_display/configuration/format.rb +8 -4
- data/lib/mods_display/configuration/genre.rb +8 -4
- data/lib/mods_display/configuration/imprint.rb +12 -7
- data/lib/mods_display/configuration/name.rb +8 -4
- data/lib/mods_display/configuration/note.rb +8 -4
- data/lib/mods_display/configuration/related_item.rb +8 -4
- data/lib/mods_display/configuration/subject.rb +11 -9
- data/lib/mods_display/configuration/title.rb +8 -4
- data/lib/mods_display/controller_extension.rb +24 -24
- data/lib/mods_display/country_codes.rb +385 -384
- data/lib/mods_display/fields/abstract.rb +7 -6
- data/lib/mods_display/fields/access_condition.rb +55 -55
- data/lib/mods_display/fields/audience.rb +7 -6
- data/lib/mods_display/fields/cartographics.rb +15 -14
- data/lib/mods_display/fields/collection.rb +32 -17
- data/lib/mods_display/fields/contact.rb +15 -13
- data/lib/mods_display/fields/contents.rb +7 -6
- data/lib/mods_display/fields/description.rb +21 -21
- data/lib/mods_display/fields/field.rb +164 -109
- data/lib/mods_display/fields/format.rb +36 -33
- data/lib/mods_display/fields/genre.rb +12 -11
- data/lib/mods_display/fields/identifier.rb +34 -34
- data/lib/mods_display/fields/imprint.rb +258 -214
- data/lib/mods_display/fields/language.rb +18 -16
- data/lib/mods_display/fields/location.rb +27 -26
- data/lib/mods_display/fields/name.rb +113 -118
- data/lib/mods_display/fields/note.rb +33 -34
- data/lib/mods_display/fields/related_item.rb +64 -66
- data/lib/mods_display/fields/resource_type.rb +13 -11
- data/lib/mods_display/fields/sub_title.rb +6 -4
- data/lib/mods_display/fields/subject.rb +92 -90
- data/lib/mods_display/fields/title.rb +54 -49
- data/lib/mods_display/fields/values.rb +7 -8
- data/lib/mods_display/html.rb +117 -96
- data/lib/mods_display/model_extension.rb +17 -16
- data/lib/mods_display/relator_codes.rb +269 -267
- data/lib/mods_display/version.rb +1 -1
- data/mods_display.gemspec +13 -12
- data/spec/configuration/access_condition_spec.rb +5 -5
- data/spec/configuration/base_spec.rb +24 -24
- data/spec/fields/abstract_spec.rb +24 -14
- data/spec/fields/access_condition_spec.rb +80 -55
- data/spec/fields/audience_spec.rb +15 -12
- data/spec/fields/cartographics_spec.rb +17 -18
- data/spec/fields/collection_spec.rb +65 -19
- data/spec/fields/contact_spec.rb +11 -9
- data/spec/fields/contents_spec.rb +15 -12
- data/spec/fields/description_spec.rb +40 -22
- data/spec/fields/format_spec.rb +28 -18
- data/spec/fields/genre_spec.rb +18 -16
- data/spec/fields/identifier_spec.rb +46 -34
- data/spec/fields/imprint_spec.rb +151 -125
- data/spec/fields/language_spec.rb +36 -20
- data/spec/fields/location_spec.rb +43 -27
- data/spec/fields/name_spec.rb +92 -92
- data/spec/fields/note_spec.rb +53 -40
- data/spec/fields/related_item_spec.rb +42 -40
- data/spec/fields/resource_type_spec.rb +20 -14
- data/spec/fields/sub_title_spec.rb +11 -9
- data/spec/fields/subject_spec.rb +61 -56
- data/spec/fields/title_spec.rb +53 -40
- data/spec/fixtures/access_condition_fixtures.rb +50 -0
- data/spec/fixtures/cartographics_fixtures.rb +1 -1
- data/spec/fixtures/imprint_fixtures.rb +49 -1
- data/spec/fixtures/name_fixtures.rb +195 -2
- data/spec/fixtures/related_item_fixtures.rb +107 -0
- data/spec/fixtures/subjects_fixtures.rb +15 -2
- data/spec/fixtures/title_fixtures.rb +101 -0
- data/spec/integration/configuration_spec.rb +23 -20
- data/spec/integration/html_spec.rb +40 -29
- data/spec/integration/installation_spec.rb +14 -14
- data/spec/spec_helper.rb +5 -8
- metadata +25 -3
@@ -0,0 +1,107 @@
|
|
1
|
+
module RelatedItemFixtures
|
2
|
+
def basic_related_item_fixture
|
3
|
+
<<-XML
|
4
|
+
<mods>
|
5
|
+
<relatedItem>
|
6
|
+
<titleInfo>A Related Item</titleInfo>
|
7
|
+
</relatedItem>
|
8
|
+
</mods>
|
9
|
+
XML
|
10
|
+
end
|
11
|
+
|
12
|
+
def linked_related_item_fixture
|
13
|
+
<<-XML
|
14
|
+
<mods>
|
15
|
+
<relatedItem>
|
16
|
+
<titleInfo>A Related Item</titleInfo>
|
17
|
+
<location>
|
18
|
+
<url>http://library.stanford.edu/</url>
|
19
|
+
</location>
|
20
|
+
</relatedItem>
|
21
|
+
</mods>
|
22
|
+
XML
|
23
|
+
end
|
24
|
+
|
25
|
+
def related_item_collection_fixture
|
26
|
+
<<-XML
|
27
|
+
<mods>
|
28
|
+
<relatedItem>
|
29
|
+
<titleInfo>This is a Collection</titleInfo>
|
30
|
+
<typeOfResource collection='yes' />
|
31
|
+
</relatedItem>
|
32
|
+
</mods>
|
33
|
+
XML
|
34
|
+
end
|
35
|
+
|
36
|
+
def related_item_display_label_fixture
|
37
|
+
<<-XML
|
38
|
+
<mods>
|
39
|
+
<relatedItem displayLabel='Special Item'>
|
40
|
+
<titleInfo>A Related Item</titleInfo>
|
41
|
+
</relatedItem>
|
42
|
+
</mods>
|
43
|
+
XML
|
44
|
+
end
|
45
|
+
|
46
|
+
def related_item_location_fixture
|
47
|
+
<<-XML
|
48
|
+
<mods>
|
49
|
+
<relatedItem>
|
50
|
+
<location>The Location</location>
|
51
|
+
</relatedItem>
|
52
|
+
</mods>
|
53
|
+
XML
|
54
|
+
end
|
55
|
+
|
56
|
+
def related_item_reference_fixture
|
57
|
+
<<-XML
|
58
|
+
<mods>
|
59
|
+
<relatedItem type='isReferencedBy'>
|
60
|
+
<titleInfo>The title</titleInfo>
|
61
|
+
<note>124</note>
|
62
|
+
<originInfo>
|
63
|
+
<dateOther>DATE</dateOther>
|
64
|
+
</originInfo>
|
65
|
+
</relatedItem>
|
66
|
+
</mods>
|
67
|
+
XML
|
68
|
+
end
|
69
|
+
|
70
|
+
def blank_related_item_fixture
|
71
|
+
<<-XML
|
72
|
+
<mods>
|
73
|
+
<relatedItem>
|
74
|
+
<titleInfo>
|
75
|
+
<title></title>
|
76
|
+
</titleInfo>
|
77
|
+
<location>
|
78
|
+
<url></url>
|
79
|
+
</location>
|
80
|
+
</relatedItem>
|
81
|
+
</mods>
|
82
|
+
XML
|
83
|
+
end
|
84
|
+
|
85
|
+
def multi_related_item_fixture
|
86
|
+
<<-XML
|
87
|
+
<mods>
|
88
|
+
<relatedItem>
|
89
|
+
<titleInfo>
|
90
|
+
<title>Library</title>
|
91
|
+
</titleInfo>
|
92
|
+
<location>
|
93
|
+
<url>http://library.stanford.edu</url>
|
94
|
+
</location>
|
95
|
+
</relatedItem>
|
96
|
+
<relatedItem>
|
97
|
+
<titleInfo>
|
98
|
+
<title>SDR</title>
|
99
|
+
</titleInfo>
|
100
|
+
<location>
|
101
|
+
<url>http://purl.stanford.edu</url>
|
102
|
+
</location>
|
103
|
+
</relatedItem>
|
104
|
+
</mods>
|
105
|
+
XML
|
106
|
+
end
|
107
|
+
end
|
@@ -10,7 +10,7 @@ module SubjectsFixtures
|
|
10
10
|
</mods>
|
11
11
|
XML
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def blank_subject
|
15
15
|
<<-XML
|
16
16
|
<mods>
|
@@ -61,6 +61,18 @@ module SubjectsFixtures
|
|
61
61
|
XML
|
62
62
|
end
|
63
63
|
|
64
|
+
def blank_name_subject
|
65
|
+
<<-XML
|
66
|
+
<mods>
|
67
|
+
<subject>
|
68
|
+
<name>
|
69
|
+
<namePart />
|
70
|
+
</name>
|
71
|
+
</subject>
|
72
|
+
</mods>
|
73
|
+
XML
|
74
|
+
end
|
75
|
+
|
64
76
|
def complex_subjects
|
65
77
|
<<-XML
|
66
78
|
<mods>
|
@@ -76,6 +88,7 @@ module SubjectsFixtures
|
|
76
88
|
</mods>
|
77
89
|
XML
|
78
90
|
end
|
91
|
+
|
79
92
|
def display_label_subjects
|
80
93
|
<<-XML
|
81
94
|
<mods>
|
@@ -99,4 +112,4 @@ module SubjectsFixtures
|
|
99
112
|
</mods>
|
100
113
|
XML
|
101
114
|
end
|
102
|
-
end
|
115
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module TitleFixtures
|
2
|
+
def simple_title_fixture
|
3
|
+
<<-XML
|
4
|
+
<mods>
|
5
|
+
<titleInfo><title>Title</title></titleInfo>
|
6
|
+
</mods>
|
7
|
+
XML
|
8
|
+
end
|
9
|
+
|
10
|
+
def title_parts_fixture
|
11
|
+
<<-XML
|
12
|
+
<mods>
|
13
|
+
<titleInfo>
|
14
|
+
<nonSort>The</nonSort>
|
15
|
+
<title>Title</title>
|
16
|
+
<subTitle>For</subTitle>
|
17
|
+
<partName>Something</partName>
|
18
|
+
<partNumber>Part 62</partNumber>
|
19
|
+
</titleInfo>
|
20
|
+
</mods>
|
21
|
+
XML
|
22
|
+
end
|
23
|
+
|
24
|
+
def reverse_title_parts_fixture
|
25
|
+
<<-XML
|
26
|
+
<mods>
|
27
|
+
<titleInfo>
|
28
|
+
<nonSort>The</nonSort>
|
29
|
+
<title>Title : </title>
|
30
|
+
<subTitle>For</subTitle>
|
31
|
+
<partNumber>Part 62</partNumber>
|
32
|
+
<partName>Something</partName>
|
33
|
+
</titleInfo>
|
34
|
+
</mods>
|
35
|
+
XML
|
36
|
+
end
|
37
|
+
|
38
|
+
def display_label_fixture
|
39
|
+
<<-XML
|
40
|
+
<mods>
|
41
|
+
<titleInfo displayLabel='MyTitle'>
|
42
|
+
<title>Title</title>
|
43
|
+
</titleInfo>
|
44
|
+
</mods>
|
45
|
+
XML
|
46
|
+
end
|
47
|
+
|
48
|
+
def display_form_fixture
|
49
|
+
<<-XML
|
50
|
+
<mods>
|
51
|
+
<titleInfo>
|
52
|
+
<title>Title</title>
|
53
|
+
<displayForm>The Title of This Item</displayForm>
|
54
|
+
</titleInfo>
|
55
|
+
</mods>
|
56
|
+
XML
|
57
|
+
end
|
58
|
+
|
59
|
+
def multi_label_fixture
|
60
|
+
<<-XML
|
61
|
+
<mods>
|
62
|
+
<titleInfo>
|
63
|
+
<title>Main Title</title>
|
64
|
+
</titleInfo>
|
65
|
+
<titleInfo type='alternative'>
|
66
|
+
<title>Alt Title</title>
|
67
|
+
</titleInfo>
|
68
|
+
<titleInfo type='uniform'>
|
69
|
+
<title>Uniform Title</title>
|
70
|
+
</titleInfo>
|
71
|
+
<titleInfo type='alternative'>
|
72
|
+
<title>Another Alt Title</title>
|
73
|
+
</titleInfo>
|
74
|
+
<titleInfo type='alternative'>
|
75
|
+
<title>Yet Another Alt Title</title>
|
76
|
+
</titleInfo>
|
77
|
+
</mods>
|
78
|
+
XML
|
79
|
+
end
|
80
|
+
|
81
|
+
def alt_title_fixture
|
82
|
+
<<-XML
|
83
|
+
<mods>
|
84
|
+
<titleInfo type='alternative'>
|
85
|
+
<title>Title</title>
|
86
|
+
</titleInfo>
|
87
|
+
</mods>
|
88
|
+
XML
|
89
|
+
end
|
90
|
+
|
91
|
+
def title_puncutation_fixture
|
92
|
+
<<-XML
|
93
|
+
<mods>
|
94
|
+
<titleInfo>
|
95
|
+
<title>A title that ends in punctuation.</title>
|
96
|
+
<partNumber>2015</partNumber>
|
97
|
+
</titleInfo>
|
98
|
+
</mods>
|
99
|
+
XML
|
100
|
+
end
|
101
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
class TestNoConfigController
|
4
4
|
include ModsDisplay::ControllerExtension
|
@@ -6,49 +6,52 @@ end
|
|
6
6
|
|
7
7
|
class TestConfigController
|
8
8
|
include ModsDisplay::ControllerExtension
|
9
|
-
|
9
|
+
|
10
10
|
configure_mods_display do
|
11
11
|
title do
|
12
12
|
label_class 'label-class'
|
13
13
|
value_class 'value-class'
|
14
|
-
link :link_to_title,
|
14
|
+
link :link_to_title, '%value%'
|
15
15
|
end
|
16
16
|
contact do
|
17
17
|
ignore!
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def link_to_title(title)
|
22
22
|
"/path/to/title?#{title}"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
26
|
+
describe 'Configuration' do
|
27
27
|
before(:all) do
|
28
|
-
xml = "<mods
|
28
|
+
xml = "<mods>
|
29
|
+
<titleInfo><title>The Title of this Item</title></titleInfo>
|
30
|
+
<note type='contact'>jdoe@example.com</note>
|
31
|
+
</mods>"
|
29
32
|
model = TestModel.new
|
30
33
|
model.modsxml = xml
|
31
34
|
@no_config_controller = TestNoConfigController.new
|
32
35
|
@config_controller = TestConfigController.new
|
33
36
|
@html = @config_controller.render_mods_display(model)
|
34
37
|
end
|
35
|
-
it
|
36
|
-
@html.
|
38
|
+
it 'should apply the label class' do
|
39
|
+
expect(@html).to match(/<dt class='label-class' title=/)
|
37
40
|
end
|
38
|
-
it
|
39
|
-
@html.scan(/<dd class='value-class'>/).length.
|
41
|
+
it 'should apply the value class' do
|
42
|
+
expect(@html.scan(/<dd class='value-class'>/).length).to eq(1)
|
40
43
|
end
|
41
|
-
it
|
42
|
-
@html.scan(
|
44
|
+
it 'should apply the link' do
|
45
|
+
@html.scan(%r{<a href='/path/to/title\?The Title of this Item'>The Title of this Item</a>})
|
43
46
|
end
|
44
|
-
it
|
45
|
-
@html.scan(/jdoe@example\.com/).length.
|
47
|
+
it 'should ignore fields if requested' do
|
48
|
+
expect(@html.scan(/jdoe@example\.com/).length).to eq(0)
|
46
49
|
end
|
47
|
-
it
|
48
|
-
@no_config_controller.mods_display_config.contact.ignore
|
49
|
-
@config_controller.mods_display_config.contact.ignore
|
50
|
+
it 'should get overriden configurations' do
|
51
|
+
expect(@no_config_controller.mods_display_config.contact.ignore?).to be false
|
52
|
+
expect(@config_controller.mods_display_config.contact.ignore?).to be true
|
50
53
|
end
|
51
|
-
it
|
52
|
-
@no_config_controller.mods_display_config.note.delimiter.
|
54
|
+
it 'should get default configurations when no controller configuration is supplied' do
|
55
|
+
expect(@no_config_controller.mods_display_config.note.delimiter).to eq('<br/>')
|
53
56
|
end
|
54
|
-
end
|
57
|
+
end
|
@@ -1,16 +1,27 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
|
-
def html_from_mods(xml, locale=nil)
|
4
|
+
def html_from_mods(xml, locale = nil)
|
5
5
|
model = TestModel.new
|
6
6
|
model.modsxml = xml
|
7
7
|
I18n.locale = locale if locale
|
8
8
|
TestController.new.render_mods_display(model)
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe 'HTML Output' do
|
12
12
|
before(:all) do
|
13
|
-
@multiple_titles = html_from_mods(
|
13
|
+
@multiple_titles = html_from_mods(
|
14
|
+
<<-MODS
|
15
|
+
<mods>
|
16
|
+
<titleInfo>
|
17
|
+
<title>Main Title</title>
|
18
|
+
</titleInfo>
|
19
|
+
<titleInfo type='alternative'>
|
20
|
+
<title>Alternate Title</title>
|
21
|
+
</titleInfo>
|
22
|
+
</mods>
|
23
|
+
MODS
|
24
|
+
)
|
14
25
|
@abstract = html_from_mods("<mods><abstract>Hey. I'm an abstract.</abstract></mods>")
|
15
26
|
mods = "<mods><titleInfo><title>Main Title</title></titleInfo><abstract>Hey. I'm an abstract.</abstract></mods>"
|
16
27
|
@mods = html_from_mods(mods)
|
@@ -19,44 +30,44 @@ describe "HTML Output" do
|
|
19
30
|
after(:all) do
|
20
31
|
I18n.locale = :en
|
21
32
|
end
|
22
|
-
describe
|
23
|
-
it
|
24
|
-
expect(@mods.to_html).to match(
|
33
|
+
describe 'i18n' do
|
34
|
+
it 'should get the default english translations' do
|
35
|
+
expect(@mods.to_html).to match(%r{<dt title='Title'>Title:</dt>})
|
25
36
|
end
|
26
|
-
it
|
27
|
-
expect(@fr_mods.to_html).to match(
|
37
|
+
it 'should internationalize the labels when translations are available' do
|
38
|
+
expect(@fr_mods.to_html).to match(%r{<dt title='Résumé'>Résumé :</dt>})
|
28
39
|
end
|
29
|
-
it
|
30
|
-
expect(@fr_mods.to_html).to match(
|
40
|
+
it 'should get fallback to the default english translations if a translation is missing' do
|
41
|
+
expect(@fr_mods.to_html).to match(%r{<dt title='Title'>Title:</dt>})
|
31
42
|
end
|
32
43
|
end
|
33
|
-
describe
|
34
|
-
it
|
35
|
-
@multiple_titles.to_html.
|
36
|
-
@multiple_titles.to_html.
|
44
|
+
describe 'titles' do
|
45
|
+
it 'should include both titles it regular display' do
|
46
|
+
expect(@multiple_titles.to_html).to include('<dd>Main Title</dd>')
|
47
|
+
expect(@multiple_titles.to_html).to include('<dd>Alternate Title</dd>')
|
37
48
|
end
|
38
|
-
it
|
39
|
-
@multiple_titles.title.
|
49
|
+
it 'should return just the first title in the #title method' do
|
50
|
+
expect(@multiple_titles.title).to eq(['Main Title'])
|
40
51
|
end
|
41
|
-
it
|
42
|
-
@multiple_titles.body.
|
43
|
-
@multiple_titles.body.
|
52
|
+
it 'should omit the first title and return any remaining titles in the #body' do
|
53
|
+
expect(@multiple_titles.body).not_to include('<dd>Main Title</dd>')
|
54
|
+
expect(@multiple_titles.body).to include('<dd>Alternate Title</dd>')
|
44
55
|
end
|
45
56
|
end
|
46
|
-
describe
|
47
|
-
it
|
57
|
+
describe 'individual fields' do
|
58
|
+
it 'should return ModsDispaly::Values for the specefied field' do
|
48
59
|
fields = @abstract.abstract
|
49
60
|
fields.each do |field|
|
50
|
-
field.
|
61
|
+
expect(field).to be_a ModsDisplay::Values
|
51
62
|
end
|
52
|
-
fields.length.
|
53
|
-
fields.first.values.
|
63
|
+
expect(fields.length).to eq 1
|
64
|
+
expect(fields.first.values).to eq ["Hey. I'm an abstract."]
|
54
65
|
end
|
55
|
-
it
|
56
|
-
@abstract.genre.
|
66
|
+
it 'should return a blank array if no data is available for a specific field' do
|
67
|
+
expect(@abstract.genre).to eq []
|
57
68
|
end
|
58
69
|
it "should not return a field that doesn't exist (and isn't a string)" do
|
59
|
-
|
70
|
+
expect { @abstract.not_a_real_field }.to raise_error NoMethodError
|
60
71
|
end
|
61
72
|
end
|
62
|
-
end
|
73
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Installation' do
|
4
4
|
before(:all) do
|
5
5
|
@pieces_of_data = 1
|
6
|
-
title_xml =
|
6
|
+
title_xml = '<mods><titleInfo><title>The Title of this Item</title></titleInfo></mods>'
|
7
7
|
model = TestModel.new
|
8
8
|
model.modsxml = title_xml
|
9
9
|
controller = TestController.new
|
10
10
|
@html = controller.render_mods_display(model)
|
11
11
|
end
|
12
|
-
it
|
13
|
-
@html.scan(/<dl>/).length.
|
14
|
-
@html.scan(
|
12
|
+
it 'should return a single <dl>' do
|
13
|
+
expect(@html.scan(/<dl>/).length).to eq(1)
|
14
|
+
expect(@html.scan(%r{</dl>}).length).to eq(1)
|
15
15
|
end
|
16
|
-
it
|
17
|
-
@html.scan(/<dt/).length.
|
18
|
-
@html.scan(/<dd>/).length.
|
16
|
+
it 'should return a dt/dd pair for each piece of metadata in the mods' do
|
17
|
+
expect(@html.scan(/<dt/).length).to eq(@pieces_of_data)
|
18
|
+
expect(@html.scan(/<dd>/).length).to eq(@pieces_of_data)
|
19
19
|
end
|
20
|
-
it
|
21
|
-
@html.scan(
|
20
|
+
it 'should return a proper label' do
|
21
|
+
expect(@html.scan(%r{<dt title='Title'>Title:</dt>}).length).to eq(1)
|
22
22
|
end
|
23
|
-
it
|
24
|
-
@html.scan(
|
23
|
+
it 'should return a proper value' do
|
24
|
+
expect(@html.scan(%r{<dd>The Title of this Item</dd>}).length).to eq(1)
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|