docx 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/docx/containers/paragraph.rb +1 -1
- data/lib/docx/document.rb +27 -1
- data/lib/docx/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bba1301a8a8e00e7fd9ee748af89280af2348120628c9a3d806dbcef78b17bb4
|
|
4
|
+
data.tar.gz: 699e0f10746445987737d090a0cf11886251f98385224dd0c9ec543b59676735
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52fd4f0aeafbf5a9ce0f5c3b4b75b8235fa291806a95dcb9455c993fe322b949aea7780a56a92ce78c2d51248eab4c6366e3511eda11991a739f53cd052460b7
|
|
7
|
+
data.tar.gz: 598be461460ae0aee15f4f13028850497df9a9bb30d47594f3ce678725095a8dd3b72ebc5cc1bb32825f10efef8c4cf27a7c54736c2875b344e0374af8daa92b
|
data/lib/docx/document.rb
CHANGED
|
@@ -22,7 +22,7 @@ module Docx
|
|
|
22
22
|
class Document
|
|
23
23
|
include Docx::SimpleInspect
|
|
24
24
|
|
|
25
|
-
attr_reader :xml, :doc, :zip, :styles
|
|
25
|
+
attr_reader :xml, :doc, :zip, :styles, :headers, :footers
|
|
26
26
|
|
|
27
27
|
def initialize(path_or_io, options = {})
|
|
28
28
|
@replace = {}
|
|
@@ -40,6 +40,8 @@ module Docx
|
|
|
40
40
|
@document_xml = document.get_input_stream.read
|
|
41
41
|
@doc = Nokogiri::XML(@document_xml)
|
|
42
42
|
load_styles
|
|
43
|
+
load_headers
|
|
44
|
+
load_footers
|
|
43
45
|
yield(self) if block_given?
|
|
44
46
|
ensure
|
|
45
47
|
@zip.close unless @zip.nil?
|
|
@@ -200,6 +202,24 @@ module Docx
|
|
|
200
202
|
Zip.write_zip64_support = previous
|
|
201
203
|
end
|
|
202
204
|
|
|
205
|
+
def load_headers
|
|
206
|
+
header_files = @zip.glob("word/header*.xml").map{|h| h.name}
|
|
207
|
+
filename_and_contents_pairs = header_files.map do |file|
|
|
208
|
+
simple_file_name = file.sub(/^word\//, "").sub(/\.xml$/, "")
|
|
209
|
+
[simple_file_name, Nokogiri::XML(@zip.read(file))]
|
|
210
|
+
end
|
|
211
|
+
@headers = Hash[filename_and_contents_pairs]
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def load_footers
|
|
215
|
+
footer_files = @zip.glob("word/footer*.xml").map{|h| h.name}
|
|
216
|
+
filename_and_contents_pairs = footer_files.map do |file|
|
|
217
|
+
simple_file_name = file.sub(/^word\//, "").sub(/\.xml$/, "")
|
|
218
|
+
[simple_file_name, Nokogiri::XML(@zip.read(file))]
|
|
219
|
+
end
|
|
220
|
+
@footers = Hash[filename_and_contents_pairs]
|
|
221
|
+
end
|
|
222
|
+
|
|
203
223
|
def load_styles
|
|
204
224
|
@styles_xml = @zip.read('word/styles.xml')
|
|
205
225
|
@styles = Nokogiri::XML(@styles_xml)
|
|
@@ -225,6 +245,12 @@ module Docx
|
|
|
225
245
|
def update
|
|
226
246
|
replace_entry 'word/document.xml', doc.serialize(save_with: 0)
|
|
227
247
|
replace_entry 'word/styles.xml', styles_configuration.serialize(save_with: 0)
|
|
248
|
+
headers.each do |name, content|
|
|
249
|
+
replace_entry "word/#{name}.xml", content.serialize(save_with: 0)
|
|
250
|
+
end
|
|
251
|
+
footers.each do |name, content|
|
|
252
|
+
replace_entry "word/#{name}.xml", content.serialize(save_with: 0)
|
|
253
|
+
end
|
|
228
254
|
end
|
|
229
255
|
|
|
230
256
|
# generate Elements::Containers::Paragraph from paragraph XML node
|
data/lib/docx/version.rb
CHANGED