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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00fd317c3d0d2f4ee4aafddd30ff41f29830f23c2e5f913c114cbc95b2bb58d1
4
- data.tar.gz: 0ad6844aeb26d84f5275f86c43bb592f821be2541e797fa1318416dd20e77bf1
3
+ metadata.gz: bba1301a8a8e00e7fd9ee748af89280af2348120628c9a3d806dbcef78b17bb4
4
+ data.tar.gz: 699e0f10746445987737d090a0cf11886251f98385224dd0c9ec543b59676735
5
5
  SHA512:
6
- metadata.gz: 32e693b1114347678865a0b5f409a745e1f4a3a195ef70d2ab6cc255022abaad79b3bed9dd66426746b2b207ab176af19178207c4e2e6af790cd8213575ee605
7
- data.tar.gz: 438dbbb6ca717e985c80f0ff4eca824c44fd1d2c94832b40121fb4423e6bf59389b03dce6d66b2f6bbbf9715e68df62c9db3db8e5a4cc60772b7cd1cdd95983d
6
+ metadata.gz: 52fd4f0aeafbf5a9ce0f5c3b4b75b8235fa291806a95dcb9455c993fe322b949aea7780a56a92ce78c2d51248eab4c6366e3511eda11991a739f53cd052460b7
7
+ data.tar.gz: 598be461460ae0aee15f4f13028850497df9a9bb30d47594f3ce678725095a8dd3b72ebc5cc1bb32825f10efef8c4cf27a7c54736c2875b344e0374af8daa92b
@@ -44,7 +44,7 @@ module Docx
44
44
 
45
45
  # Return paragraph as a <p></p> HTML fragment with formatting based on properties.
46
46
  def to_html
47
- html = ''
47
+ html = +''
48
48
  text_runs.each do |text_run|
49
49
  html << text_run.to_html
50
50
  end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Docx #:nodoc:
4
- VERSION = '0.10.1'
4
+ VERSION = '0.11.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Hunt