docx 0.11.0 → 0.12.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: bba1301a8a8e00e7fd9ee748af89280af2348120628c9a3d806dbcef78b17bb4
4
- data.tar.gz: 699e0f10746445987737d090a0cf11886251f98385224dd0c9ec543b59676735
3
+ metadata.gz: 16df363293a0fcb4945e4ab7aa968f7138f2d0e38d25bcf689a5c5142279e520
4
+ data.tar.gz: '089d8ef9c78a7ae13d980d3a78ce729b05fe6dff1fefe8bbdfe4488a6b7b0f91'
5
5
  SHA512:
6
- metadata.gz: 52fd4f0aeafbf5a9ce0f5c3b4b75b8235fa291806a95dcb9455c993fe322b949aea7780a56a92ce78c2d51248eab4c6366e3511eda11991a739f53cd052460b7
7
- data.tar.gz: 598be461460ae0aee15f4f13028850497df9a9bb30d47594f3ce678725095a8dd3b72ebc5cc1bb32825f10efef8c4cf27a7c54736c2875b344e0374af8daa92b
6
+ metadata.gz: 8a23b154632578c3a702d3e16b6bbc3d763f062860ea9cf8db6c6814e89c1e7d99073fa28b7f90276c883d5c1f47be9d688d6f05177c06dbfc3bc452ccadc371
7
+ data.tar.gz: a8a735936caad5c75f56cace55e980df01bb25af795d5b8d040b735b14510898b220da3b8f40c52b74c68dc371c9a2d25bc2791d44a54a74dde9db727d3432ae
data/README.md CHANGED
@@ -5,13 +5,13 @@
5
5
  [![Coverage Status](https://coveralls.io/repos/github/ruby-docx/docx/badge.svg?branch=master)](https://coveralls.io/github/ruby-docx/docx?branch=master)
6
6
  [![Gitter](https://badges.gitter.im/ruby-docx/community.svg)](https://gitter.im/ruby-docx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
7
7
 
8
- A ruby library/gem for interacting with `.docx` files. currently capabilities include reading paragraphs/bookmarks, inserting text at bookmarks, reading tables/rows/columns/cells and saving the document.
8
+ A ruby library/gem for interacting with `.docx` files. currently capabilities include reading paragraphs/bookmarks, inserting text at bookmarks, reading and writing headers/footers, reading tables/rows/columns/cells and saving the document.
9
9
 
10
10
  ## Usage
11
11
 
12
12
  ### Prerequisites
13
13
 
14
- - Ruby 2.6 or later
14
+ - Ruby 2.7 or later
15
15
 
16
16
  ### Install
17
17
 
@@ -63,6 +63,26 @@ doc = Docx::Document.open(buffer)
63
63
  # Everything about reading is the same as shown above
64
64
  ```
65
65
 
66
+ ### Reading headers and footers
67
+
68
+ ``` ruby
69
+ require 'docx'
70
+
71
+ doc = Docx::Document.open('example.docx')
72
+
73
+ # Headers and footers are returned as hashes keyed by their file name
74
+ # (e.g. "header1", "footer1"), with Nokogiri documents as values.
75
+ doc.headers.each do |name, header|
76
+ puts name
77
+ puts header.text
78
+ end
79
+
80
+ doc.footers.each do |name, footer|
81
+ puts name
82
+ puts footer.text
83
+ end
84
+ ```
85
+
66
86
  ### Rendering html
67
87
  ``` ruby
68
88
  require 'docx'
@@ -116,7 +136,11 @@ doc = Docx::Document.open('example.docx')
116
136
  doc.bookmarks['example_bookmark'].insert_text_after("Hello world.")
117
137
 
118
138
  # Insert multiple lines of text at our bookmark
119
- doc.bookmarks['example_bookmark_2'].insert_multiple_lines_after(['Hello', 'World', 'foo'])
139
+ doc.bookmarks['example_bookmark_2'].insert_multiple_lines(['Hello', 'World', 'foo'])
140
+
141
+ # Bookmarks placed in headers and footers are included too, and edits to them
142
+ # are saved along with the document.
143
+ doc.bookmarks['header_bookmark'].insert_text_after("Hello from the header.")
120
144
 
121
145
  # Remove paragraphs
122
146
  doc.paragraphs.each do |p|
data/lib/docx/document.rb CHANGED
@@ -70,6 +70,9 @@ module Docx
70
70
  def bookmarks
71
71
  bkmrks_hsh = {}
72
72
  bkmrks_ary = @doc.xpath('//w:bookmarkStart').map { |b_node| parse_bookmark_from b_node }
73
+ # also scan headers and footers so their bookmarks can be read and edited
74
+ bkmrks_ary += headers.values.flat_map { |h| h.xpath('//w:bookmarkStart').map { |b_node| parse_bookmark_from b_node } }
75
+ bkmrks_ary += footers.values.flat_map { |f| f.xpath('//w:bookmarkStart').map { |b_node| parse_bookmark_from b_node } }
73
76
  # auto-generated by office 2010
74
77
  bkmrks_ary.reject! { |b| b.name == '_GoBack' }
75
78
  bkmrks_ary.each { |b| bkmrks_hsh[b.name] = b }
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.11.0'
4
+ VERSION = '0.12.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.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Hunt