Files
Notare/lib/ezdoc/xml/relationships.rb
2025-12-02 11:43:25 +01:00

56 lines
1.6 KiB
Ruby

# frozen_string_literal: true
module Ezdoc
module Xml
class Relationships
NAMESPACE = "http://schemas.openxmlformats.org/package/2006/relationships"
def to_xml
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
xml.Relationships(xmlns: NAMESPACE) do
xml.Relationship(
Id: "rId1",
Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
Target: "word/document.xml"
)
end
end
builder.to_xml
end
end
class DocumentRelationships
NAMESPACE = "http://schemas.openxmlformats.org/package/2006/relationships"
IMAGE_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
def initialize(has_numbering: false, images: [])
@has_numbering = has_numbering
@images = images
end
def to_xml
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
xml.Relationships(xmlns: NAMESPACE) do
if @has_numbering
xml.Relationship(
Id: "rId1",
Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
Target: "numbering.xml"
)
end
@images.each do |image|
xml.Relationship(
Id: image.rid,
Type: IMAGE_TYPE,
Target: "media/#{image.filename}"
)
end
end
end
builder.to_xml
end
end
end
end