Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove special handling of childless divs #5145

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions app/models/iiif_canvas_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ def simple_iiif_range(label = stream_info[:embed_title])
end

def structure_to_iiif_range
# Remove all "Div" nodes which do not have a "Span" descendant to ensure a valid manifest.
# According the to IIIF presentation 3 spec each Range needs to have a descendant that is a Canvas.
# See https://iiif.io/api/presentation/3.0/#34-structural-properties
structure_ng_xml.root.xpath("//*[local-name() = 'Div' and not(descendant::*[local-name() = 'Span'])]").map(&:remove)

# Return default range if nothing valid is left
return simple_iiif_range(structure_ng_xml.root.attr('label')) if structure_ng_xml.root.children.all?(&:blank?)

div_to_iiif_range(structure_ng_xml.root)
end

Expand All @@ -114,10 +106,6 @@ def div_to_iiif_range(div_node)
end
end

# if a non-leaf node has no valid "Div" or "Span" children, then it would become empty range node containing no canvas
# raise an exception here as this error shall have been caught and handled by the parser and shall never happen here
raise Nokogiri::XML::SyntaxError, "Empty root or Div node: #{div_node[:label]}" if items.empty?

IiifManifestRange.new(
label: { "none" => [div_node[:label]] },
items: items
Expand Down
26 changes: 0 additions & 26 deletions spec/models/iiif_canvas_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,5 @@
expect(subject.items.first.media_fragment).to eq 't=0,'
end
end

context 'with invalid structural metadata' do
let(:structure_xml) { '<?xml version="1.0"?><Item label="Test"><Div label="Bad"/><Div label="Div 1"><Div label="Also bad"/><Span label="Span 1" begin="00:00:00.000" end="00:00:01.235"/></Div></Item>' }

it 'removes ranges without descendant canvases' 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'
end

context 'when there are no valid ranges' do
let(:structure_xml) { '<?xml version="1.0"?><Item label="Test"><Div label="Div 1"/></Item>' }

it 'autogenerates a basic range but preserves the root level label' do
expect(subject.label.to_s).to eq '{"none"=>["Test"]}'
expect(subject.items.size).to eq 1
expect(subject.items.first).to be_a IiifCanvasPresenter
expect(subject.items.first.media_fragment).to eq 't=0,'
end
end
end
end
end