diff --git a/app/models/iiif_canvas_presenter.rb b/app/models/iiif_canvas_presenter.rb index 6fc9849e6f..6c24876d21 100644 --- a/app/models/iiif_canvas_presenter.rb +++ b/app/models/iiif_canvas_presenter.rb @@ -139,9 +139,7 @@ def structure_to_iiif_range def root_to_iiif_range(root_node) range = div_to_iiif_range(root_node) - if only_empty_descendants?(root_node) - range.items.prepend(IiifCanvasPresenter.new(master_file: master_file, stream_info: stream_info, media_fragment: "t=0,#{stream_info[:duration]}")) - end + range.items.prepend(IiifCanvasPresenter.new(master_file: master_file, stream_info: stream_info, media_fragment: "t=0,#{stream_info[:duration]}")) return range end @@ -171,10 +169,6 @@ def span_to_iiif_range(span_node) ) end - def only_empty_descendants?(node) - node.xpath('.//Span').empty? - end - FLOAT_PATTERN = Regexp.new(/^\d+([.]\d*)?$/).freeze def parse_hour_min_sec(s) diff --git a/spec/models/iiif_canvas_presenter_spec.rb b/spec/models/iiif_canvas_presenter_spec.rb index ae8af87880..2c4099f997 100644 --- a/spec/models/iiif_canvas_presenter_spec.rb +++ b/spec/models/iiif_canvas_presenter_spec.rb @@ -74,15 +74,17 @@ master_file.structuralMetadata.content = structure_xml end - it 'converts stored xml into IIIF ranges' do + it 'converts stored xml into IIIF ranges with canvas reference in root range' do expect(subject.label.to_s).to eq '{"none"=>["Test"]}' - expect(subject.items.size).to eq 1 - expect(subject.items.first.label.to_s).to eq '{"none"=>["Div 1"]}' - expect(subject.items.first.items.size).to eq 1 - expect(subject.items.first.items.first.label.to_s).to eq '{"none"=>["Span 1"]}' - expect(subject.items.first.items.first.items.size).to eq 1 - expect(subject.items.first.items.first.items.first).to be_a IiifCanvasPresenter - expect(subject.items.first.items.first.items.first.media_fragment).to eq 't=0.0,1.235' + expect(subject.items.size).to eq 2 + expect(subject.items.first).to be_a IiifCanvasPresenter + expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}" + expect(subject.items.second.label.to_s).to eq '{"none"=>["Div 1"]}' + expect(subject.items.second.items.size).to eq 1 + expect(subject.items.second.items.first.label.to_s).to eq '{"none"=>["Span 1"]}' + expect(subject.items.second.items.first.items.size).to eq 1 + expect(subject.items.second.items.first.items.first).to be_a IiifCanvasPresenter + expect(subject.items.second.items.first.items.first.media_fragment).to eq 't=0.0,1.235' end context 'with no structural metadata' do @@ -117,19 +119,21 @@ context 'with spans' do let(:structure_xml) { '
' } - it 'does not generate a canvas reference in the root range' do + it 'generates a canvas reference in the root range' do expect(subject.label.to_s).to eq '{"none"=>["Test"]}' - expect(subject.items.size).to eq 1 - expect(subject.items.first.label.to_s).to eq '{"none"=>["Div 1"]}' - expect(subject.items.first.items.size).to eq 2 - expect(subject.items.first.items.first.label.to_s).to eq '{"none"=>["Div 2"]}' - expect(subject.items.first.items.first.items.size).to eq 1 - expect(subject.items.first.items.first.items.first.label.to_s).to eq '{"none"=>["Div 3"]}' - expect(subject.items.first.items.first.items.first.items.size).to eq 0 - expect(subject.items.first.items.second.label.to_s).to eq '{"none"=>["Span 1"]}' - expect(subject.items.first.items.second.items.size).to eq 1 - expect(subject.items.first.items.second.items.first).to be_a IiifCanvasPresenter - expect(subject.items.first.items.second.items.first.media_fragment).to eq 't=0.0,1.235' + expect(subject.items.size).to eq 2 + expect(subject.items.first).to be_a IiifCanvasPresenter + expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}" + expect(subject.items.second.label.to_s).to eq '{"none"=>["Div 1"]}' + expect(subject.items.second.items.size).to eq 2 + expect(subject.items.second.items.first.label.to_s).to eq '{"none"=>["Div 2"]}' + expect(subject.items.second.items.first.items.size).to eq 1 + expect(subject.items.second.items.first.items.first.label.to_s).to eq '{"none"=>["Div 3"]}' + expect(subject.items.second.items.first.items.first.items.size).to eq 0 + expect(subject.items.second.items.second.label.to_s).to eq '{"none"=>["Span 1"]}' + expect(subject.items.second.items.second.items.size).to eq 1 + expect(subject.items.second.items.second.items.first).to be_a IiifCanvasPresenter + expect(subject.items.second.items.second.items.first.media_fragment).to eq 't=0.0,1.235' end end end