mods_display 0.0.1.beta5 → 0.0.1.beta6

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,5 +22,6 @@ require "mods_display/fields/note"
22
22
  require "mods_display/fields/related_item"
23
23
  require "mods_display/fields/related_location"
24
24
  require "mods_display/fields/subject"
25
+ require "mods_display/fields/sub_title"
25
26
  require "mods_display/fields/title"
26
27
  require "mods_display/fields/values"
@@ -1,3 +1,5 @@
1
+ # We can probably do something smarter here using const_get to assign
2
+ # special coniguration classes then fall back on the base config class
1
3
  class ModsDisplay::Configuration
2
4
  def initialize &config
3
5
  instance_eval &config
@@ -7,6 +9,10 @@ class ModsDisplay::Configuration
7
9
  @title ||= ModsDisplay::Configuration::Base.new(&title || Proc.new{})
8
10
  end
9
11
 
12
+ def sub_title &sub_title
13
+ @sub_title ||= ModsDisplay::Configuration::Base.new(&sub_title || Proc.new{})
14
+ end
15
+
10
16
  def name &name
11
17
  @name ||= ModsDisplay::Configuration::Base.new(&name || Proc.new{})
12
18
  end
@@ -0,0 +1,5 @@
1
+ class ModsDisplay::SubTitle < ModsDisplay::Field
2
+ def fields
3
+ ModsDisplay::Title.new(@value[1, @value.length], @config, @klass).fields
4
+ end
5
+ end
@@ -18,7 +18,9 @@ class ModsDisplay::HTML
18
18
  # and replace the first key in the the fields list with that.
19
19
  def body
20
20
  output = "<dl>"
21
- mods_display_fields.each do |field_key|
21
+ body_fields = mods_display_fields.dup
22
+ body_fields[0] = :subTitle
23
+ body_fields.each do |field_key|
22
24
  unless mods_field(@xml, field_key).to_html.nil?
23
25
  output << mods_field(@xml, field_key).to_html
24
26
  end
@@ -67,6 +69,7 @@ class ModsDisplay::HTML
67
69
 
68
70
  def mods_display_field_mapping
69
71
  {:title => :title_info,
72
+ :subTitle => :title_info,
70
73
  :name => :plain_name,
71
74
  :format => :typeOfResource,
72
75
  :imprint => :origin_info,
@@ -86,8 +89,9 @@ class ModsDisplay::HTML
86
89
  end
87
90
 
88
91
  def field_key_translation
89
- {:relatedLocation => :related_location,
90
- :relatedItem => :related_item
92
+ {:subTitle => :sub_title,
93
+ :relatedLocation => :related_location,
94
+ :relatedItem => :related_item
91
95
  }
92
96
  end
93
97
 
@@ -1,3 +1,3 @@
1
1
  module ModsDisplay
2
- VERSION = "0.0.1.beta5"
2
+ VERSION = "0.0.1.beta6"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ def mods_display_sub_title(mods_record)
4
+ ModsDisplay::SubTitle.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
5
+ end
6
+
7
+ describe ModsDisplay::SubTitle do
8
+ before(:all) do
9
+ @title = Stanford::Mods::Record.new.from_str("<mods><titleInfo><title>Main Title</title></titleInfo><titleInfo><title>Sub Title</title></titleInfo></mods>", false).title_info
10
+ end
11
+ it "omit the main title and only return sub titles" do
12
+ fields = mods_display_sub_title(@title).fields
13
+ fields.length.should == 1
14
+ fields.first.label.should == "Title"
15
+ fields.first.values.should == ["Sub Title"]
16
+
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ def html_from_mods(xml)
4
+ model = TestModel.new
5
+ model.modsxml = xml
6
+ TestController.new.render_mods_display(model)
7
+ end
8
+
9
+ describe "HTML Output" do
10
+ before(:all) do
11
+ @multiple_titles = html_from_mods("<mods><titleInfo><title>Main Title</title></titleInfo><titleInfo type='alternative'><title>Alternate Title</title></titleInfo></mods>")
12
+ end
13
+
14
+ describe "titles" do
15
+ it "should include both titles it regular display" do
16
+ @multiple_titles.to_html.should include("<dd>Main Title</dd>")
17
+ @multiple_titles.to_html.should include("<dd>Alternate Title</dd>")
18
+ end
19
+ it "should return just the first title in the #title method" do
20
+ @multiple_titles.title.should == ["Main Title"]
21
+ end
22
+ it "should omit the first title and return any remaining titles in the #body" do
23
+ @multiple_titles.body.should_not include("<dd>Main Title</dd>")
24
+ @multiple_titles.body.should include("<dd>Alternate Title</dd>")
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta5
4
+ version: 0.0.1.beta6
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-13 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stanford-mods
@@ -93,6 +93,7 @@ files:
93
93
  - lib/mods_display/fields/note.rb
94
94
  - lib/mods_display/fields/related_item.rb
95
95
  - lib/mods_display/fields/related_location.rb
96
+ - lib/mods_display/fields/sub_title.rb
96
97
  - lib/mods_display/fields/subject.rb
97
98
  - lib/mods_display/fields/title.rb
98
99
  - lib/mods_display/fields/values.rb
@@ -116,6 +117,7 @@ files:
116
117
  - spec/fields/note_spec.rb
117
118
  - spec/fields/related_item_spec.rb
118
119
  - spec/fields/related_location_spec.rb
120
+ - spec/fields/sub_title_spec.rb
119
121
  - spec/fields/subject_spec.rb
120
122
  - spec/fields/title_spec.rb
121
123
  - spec/fixtures/cartographics_fixtures.rb
@@ -123,6 +125,7 @@ files:
123
125
  - spec/fixtures/name_fixtures.rb
124
126
  - spec/fixtures/subjects_fixtures.rb
125
127
  - spec/integration/configuration_spec.rb
128
+ - spec/integration/html_spec.rb
126
129
  - spec/integration/installation_spec.rb
127
130
  - spec/spec_helper.rb
128
131
  homepage: ''
@@ -139,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
142
  version: '0'
140
143
  segments:
141
144
  - 0
142
- hash: -354569883239195069
145
+ hash: -2853420712234504554
143
146
  required_rubygems_version: !ruby/object:Gem::Requirement
144
147
  none: false
145
148
  requirements:
@@ -171,6 +174,7 @@ test_files:
171
174
  - spec/fields/note_spec.rb
172
175
  - spec/fields/related_item_spec.rb
173
176
  - spec/fields/related_location_spec.rb
177
+ - spec/fields/sub_title_spec.rb
174
178
  - spec/fields/subject_spec.rb
175
179
  - spec/fields/title_spec.rb
176
180
  - spec/fixtures/cartographics_fixtures.rb
@@ -178,5 +182,6 @@ test_files:
178
182
  - spec/fixtures/name_fixtures.rb
179
183
  - spec/fixtures/subjects_fixtures.rb
180
184
  - spec/integration/configuration_spec.rb
185
+ - spec/integration/html_spec.rb
181
186
  - spec/integration/installation_spec.rb
182
187
  - spec/spec_helper.rb