Project rename
All checks were successful
CI Pipeline / build (push) Successful in 12s

This commit is contained in:
2025-12-02 13:21:13 +01:00
parent 29ebb9a8d1
commit dec346254c
36 changed files with 114 additions and 114 deletions

63
lib/notare/package.rb Normal file
View File

@@ -0,0 +1,63 @@
# frozen_string_literal: true
require "zip"
module Notare
class Package
def initialize(document)
@document = document
end
def save(path)
Zip::File.open(path, Zip::File::CREATE) do |zipfile|
zipfile.get_output_stream("[Content_Types].xml") { |f| f.write(content_types_xml) }
zipfile.get_output_stream("_rels/.rels") { |f| f.write(relationships_xml) }
zipfile.get_output_stream("word/_rels/document.xml.rels") { |f| f.write(document_relationships_xml) }
zipfile.get_output_stream("word/document.xml") { |f| f.write(document_xml) }
zipfile.get_output_stream("word/styles.xml") { |f| f.write(styles_xml) }
zipfile.get_output_stream("word/numbering.xml") { |f| f.write(numbering_xml) } if lists?
images.each do |image|
zipfile.get_output_stream("word/media/#{image.filename}") do |f|
f.write(File.binread(image.path))
end
end
end
end
private
def lists?
@document.lists.any?
end
def images
@document.images
end
def content_types_xml
Xml::ContentTypes.new(has_numbering: lists?, images: images, has_styles: true).to_xml
end
def relationships_xml
Xml::Relationships.new.to_xml
end
def document_relationships_xml
Xml::DocumentRelationships.new(has_numbering: lists?, images: images, has_styles: true).to_xml
end
def document_xml
Xml::DocumentXml.new(@document.nodes).to_xml
end
def styles_xml
Xml::StylesXml.new(@document.styles).to_xml
end
def numbering_xml
Xml::Numbering.new(@document.lists).to_xml
end
end
end