From a2ff60a186bcc272e329e9649af60f4ba2e45939 Mon Sep 17 00:00:00 2001 From: Yousuf Jukaku Date: Thu, 1 Mar 2018 11:12:01 -0500 Subject: [PATCH] Allow access to numbering.xml, header1.xml, and footer1.xml docs --- lib/docx/document.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/docx/document.rb b/lib/docx/document.rb index a5722d3..41e539c 100755 --- a/lib/docx/document.rb +++ b/lib/docx/document.rb @@ -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 = {} @@ -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