docx 0.6.0 → 0.6.2

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: 6dd59a023e1430fce917809931fe955651324db4fadb7a55d9a380731240466e
4
- data.tar.gz: eb91759397bdc0782691c6ed46b37a67a031ab580d590568a7f221a223d2f80c
3
+ metadata.gz: 2a33dcd9e31c60144261a15670cd1c01b37877044aaf33f7091b46cc85ab3412
4
+ data.tar.gz: 1911db027b3e2fbf8eb9363eaa99b95231f875afe8de2a0c060b38fee86c7238
5
5
  SHA512:
6
- metadata.gz: c722c427338ceb1f4d8c926c4e3b2a8c2b2de9889e77a9b78fec4ffe2270b633dfd8f843a31ed17a77b6b5d09d9e9d8b4c88e52569b3c410d1f8ae9183c76c6d
7
- data.tar.gz: 41af211af034071991a920f1ed00e9ee9c8e5e739f41553c8b263081e7626183bc21e38735bfed88f01fdea0599f13a313cfc0ea1f9cc8331edff97e5cd5c40d
6
+ metadata.gz: 0a823fedf1b0bfc542c88533c787aefa5e9cee12ae4422a01f106985a2f03e8b636aa70820a179f5501ba8f996672f8f75e24356282cd7d81505cbb1984fa967
7
+ data.tar.gz: c06b4078536bd8b12b5c5e4f61fe0ef5f2f9e03e9cbc7c4017f2d01d3e8a0bc9200fa7457fac54c0b110a57ddc4bff8ad74c28d3e873512900266ac00137c6e6
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # docx
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/docx.svg)](https://badge.fury.io/rb/docx)
4
- [![Build Status](https://travis-ci.org/ruby-docx/docx.svg?branch=master)](https://travis-ci.org/ruby-docx/docx)
4
+ [![Ruby](https://github.com/ruby-docx/docx/workflows/Ruby/badge.svg)](https://github.com/ruby-docx/docx/actions?query=workflow%3ARuby)
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
 
@@ -11,7 +11,7 @@ A ruby library/gem for interacting with `.docx` files. currently capabilities in
11
11
 
12
12
  ### Prerequisites
13
13
 
14
- - Ruby 2.4 or later
14
+ - Ruby 2.5 or later
15
15
 
16
16
  ### Install
17
17
 
@@ -134,6 +134,35 @@ end
134
134
  doc.save('example-edited.docx')
135
135
  ```
136
136
 
137
+ ### Writing to tables
138
+
139
+ ``` ruby
140
+ require 'docx'
141
+
142
+ # Create a Docx::Document object for our existing docx file
143
+ doc = Docx::Document.open('tables.docx')
144
+
145
+ # Iterate over each table
146
+ doc.tables.each do |table|
147
+ last_row = table.rows.last
148
+
149
+ # Copy last row and insert a new one before last row
150
+ new_row = last_row.copy
151
+ new_row.insert_before(last_row)
152
+
153
+ # Substitute text in each cell of this new row
154
+ new_row.cells.each do |cell|
155
+ cell.paragraphs.each do |paragraph|
156
+ paragraph.each_text_run do |text|
157
+ text.substitute('_placeholder_', 'replacement value')
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ doc.save('tables-edited.docx')
164
+ ```
165
+
137
166
  ### Advanced
138
167
 
139
168
  ``` ruby
data/lib/docx/document.rb CHANGED
@@ -30,8 +30,7 @@ module Docx
30
30
  @zip = Zip::File.open_buffer(path_or_io)
31
31
  end
32
32
 
33
- document = @zip.find_entry('word/document.xml')
34
- document ||= @zip.find_entry('word/document2.xml')
33
+ document = @zip.glob('word/document*.xml').first
35
34
  raise Errno::ENOENT if document.nil?
36
35
 
37
36
  @document_xml = document.get_input_stream.read
@@ -88,12 +87,12 @@ module Docx
88
87
  def hyperlinks
89
88
  hyperlink_relationships.each_with_object({}) do |rel, hash|
90
89
  hash[rel.attributes['Id'].value] = rel.attributes['Target'].value
91
- end
90
+ end
92
91
  end
93
92
 
94
93
  def hyperlink_relationships
95
94
  @rels.xpath("//xmlns:Relationship[contains(@Type,'hyperlink')]")
96
- end
95
+ end
97
96
 
98
97
  ##
99
98
  # *Deprecated*
@@ -169,13 +168,20 @@ module Docx
169
168
  def load_styles
170
169
  @styles_xml = @zip.read('word/styles.xml')
171
170
  @styles = Nokogiri::XML(@styles_xml)
172
- @rels_xml = @zip.read('word/_rels/document.xml.rels')
173
- @rels = Nokogiri::XML(@rels_xml)
171
+ load_rels
174
172
  rescue Errno::ENOENT => e
175
173
  warn e.message
176
174
  nil
177
175
  end
178
176
 
177
+ def load_rels
178
+ rels_entry = @zip.glob('word/_rels/document*.xml.rels').first
179
+ raise Errno::ENOENT unless rels_entry
180
+
181
+ @rels_xml = rels_entry.get_input_stream.read
182
+ @rels = Nokogiri::XML(@rels_xml)
183
+ end
184
+
179
185
  #--
180
186
  # TODO: Flesh this out to be compatible with other files
181
187
  # TODO: Method to set flag on files that have been edited, probably by inserting something at the
data/lib/docx/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Docx #:nodoc:
2
- VERSION = '0.6.0'
4
+ VERSION = '0.6.2'
3
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.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Hunt
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2020-10-14 00:00:00.000000000 Z
15
+ date: 2021-07-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri
@@ -49,19 +49,19 @@ dependencies:
49
49
  - !ruby/object:Gem::Version
50
50
  version: '2.0'
51
51
  - !ruby/object:Gem::Dependency
52
- name: coveralls
52
+ name: coveralls_reborn
53
53
  requirement: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: '0.8'
57
+ version: '0.21'
58
58
  type: :development
59
59
  prerelease: false
60
60
  version_requirements: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - "~>"
63
63
  - !ruby/object:Gem::Version
64
- version: '0.8'
64
+ version: '0.21'
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: rake
67
67
  requirement: !ruby/object:Gem::Requirement
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.1.2
138
+ rubygems_version: 3.1.6
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: a ruby library/gem for interacting with .docx files