39 lines
942 B
Ruby
39 lines
942 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "zip"
|
|
|
|
module Ezdoc
|
|
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) }
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def content_types_xml
|
|
Xml::ContentTypes.new.to_xml
|
|
end
|
|
|
|
def relationships_xml
|
|
Xml::Relationships.new.to_xml
|
|
end
|
|
|
|
def document_relationships_xml
|
|
Xml::DocumentRelationships.new.to_xml
|
|
end
|
|
|
|
def document_xml
|
|
Xml::DocumentXml.new(@document.content).to_xml
|
|
end
|
|
end
|
|
end
|