Initial project setup
This commit is contained in:
34
lib/ezdoc/xml/document_xml.rb
Normal file
34
lib/ezdoc/xml/document_xml.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Ezdoc
|
||||
module Xml
|
||||
class DocumentXml
|
||||
NAMESPACES = {
|
||||
"xmlns:w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
||||
"xmlns:r" => "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
||||
}.freeze
|
||||
|
||||
def initialize(content)
|
||||
@content = content
|
||||
end
|
||||
|
||||
def to_xml
|
||||
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
||||
xml.document(NAMESPACES) do
|
||||
xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == "w" }
|
||||
xml["w"].body do
|
||||
@content.each do |item|
|
||||
xml["w"].p do
|
||||
xml["w"].r do
|
||||
xml["w"].t item[:text]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
builder.to_xml
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user