Skip to content
Merged
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
17 changes: 16 additions & 1 deletion lib/docx/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ module Docx
# puts d.text
# end
class Document
attr_reader :xml, :doc, :zip, :styles

DOCUMENT_PATHS = {
header: "word/header1.xml",
footer: "word/footer1.xml",
numbering: "word/numbering.xml",
}

attr_reader :xml, :doc, :zip, :styles, :header, :footer, :numbering

def initialize(path, &block)
@replace = {}
Expand All @@ -27,6 +34,14 @@ def initialize(path, &block)
@doc = Nokogiri::XML(@document_xml)
@styles_xml = @zip.read('word/styles.xml')
@styles = Nokogiri::XML(@styles_xml)

DOCUMENT_PATHS.each do |attr_name, path|
if @zip.find_entry(path)
xml_doc = @zip.read(path)
self.instance_variable_set(:"@#{attr_name}", Nokogiri::XML(xml_doc))
end
end

if block_given?
yield self
@zip.close
Expand Down