Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to numbering.xml, header1.xml, and footer1.xml docs #1

Merged
merged 1 commit into from
Mar 1, 2018
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