docx 0.9.1 → 0.10.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: f170295a0362d6fcbbe6313ddd9f3ccf50379eb220ab52b26caee581786471a4
4
- data.tar.gz: f6050fc0a2959392184da37012e0a2efcb5290f8bb1d015510e9dd52abf71ee7
3
+ metadata.gz: 9fc798e71a79265389a2dcf22d0ecff1268a920f92463c23b9ccbce94517b7be
4
+ data.tar.gz: 1b21fef113ce8a84a7aeaf97b05139822763a4ac96835efd59971b52fb34ce98
5
5
  SHA512:
6
- metadata.gz: de8c52dced6b5d95b7fa3d34ab8c124ce5e1539fc5874fac1b5a71d31c3f7c46af7b27cc53bd89960f122a01a5a36372825f91acd8c1d0cae715f7380a2b7625
7
- data.tar.gz: bb39bab159ac4f5ccec77ddd3c64bd9a1a8863f80a948c7d963cfde2e6904ecc112f2c4c79e080dbfc37b2580ecc37ab4249c0d303f945a02ccae432a33671fc
6
+ metadata.gz: eab6dae181b61b9b7103460a4e5d582ef534b36f2f09cbfaba9c5ef16d880b9bca6a97d76e7c671fbb24a897189e6b1861a6f4874e589075d781b3a660e796c9
7
+ data.tar.gz: ca39d10248be1d18d173293fc8a918fe86e615cbd6fbdb5340a532792d9ef478ac563fb3ef61a6fdd4e1542a9d7258015e5bc34ecd69c86e6edb39ce422ec636
data/README.md CHANGED
@@ -52,7 +52,7 @@ doc.bookmarks.each_pair do |bookmark_name, bookmark_object|
52
52
  end
53
53
  ```
54
54
 
55
- Don't have a local file but a buffer? Docx handles those to:
55
+ Don't have a local file but a buffer? Docx handles those too:
56
56
 
57
57
  ```ruby
58
58
  require 'docx'
@@ -130,6 +130,14 @@ doc.paragraphs.each do |p|
130
130
  end
131
131
  end
132
132
 
133
+ # Substitute text with access to captures, note block arg is a MatchData, a bit
134
+ # different than String.gsub. https://ruby-doc.org/3.3.7/MatchData.html
135
+ doc.paragraphs.each do |p|
136
+ p.each_text_run do |tr|
137
+ tr.substitute_with_block(/total: (\d+)/) { |match_data| "total: #{match_data[1].to_i * 10}" }
138
+ end
139
+ end
140
+
133
141
  # Save document to specified path
134
142
  doc.save('example-edited.docx')
135
143
  ```
@@ -145,7 +153,7 @@ doc = Docx::Document.open('tables.docx')
145
153
  # Iterate over each table
146
154
  doc.tables.each do |table|
147
155
  last_row = table.rows.last
148
-
156
+
149
157
  # Copy last row and insert a new one before last row
150
158
  new_row = last_row.copy
151
159
  new_row.insert_before(last_row)
@@ -261,3 +269,4 @@ The following is a list of attributes and what they control within the style.
261
269
  * Default formatting of inserted elements to inherited values
262
270
  * Implement formattable elements.
263
271
  * Easier multi-line text insertion at a single bookmark (inserting paragraph nodes after the one containing the bookmark)
272
+
@@ -57,6 +57,19 @@ module Docx
57
57
  reset_text
58
58
  end
59
59
 
60
+ # Weird things with how $1/$2 in regex blocks are handled means we can't just delegate
61
+ # block to gsub to get block, we have to do it this way, with a block that gets a MatchData,
62
+ # from which captures and other match data can be retrieved.
63
+ # https://ruby-doc.org/3.3.7/MatchData.html
64
+ def substitute_with_block(match, &block)
65
+ @text_nodes.each do |text_node|
66
+ text_node.content = text_node.content.gsub(match) { |_unused_matched_string|
67
+ block.call(Regexp.last_match)
68
+ }
69
+ end
70
+ reset_text
71
+ end
72
+
60
73
  def parse_formatting
61
74
  {
62
75
  italic: !@node.xpath('.//w:i').empty?,
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.9.1'
4
+ VERSION = '0.10.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.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Hunt
@@ -11,7 +11,7 @@ authors:
11
11
  - Sebastian Wittenkamp
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2025-05-03 00:00:00.000000000 Z
14
+ date: 1980-01-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: nokogiri
@@ -37,16 +37,22 @@ dependencies:
37
37
  name: rubyzip
38
38
  requirement: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2.0'
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '4'
43
46
  type: :runtime
44
47
  prerelease: false
45
48
  version_requirements: !ruby/object:Gem::Requirement
46
49
  requirements:
47
- - - "~>"
50
+ - - ">="
48
51
  - !ruby/object:Gem::Version
49
52
  version: '2.0'
53
+ - - "<"
54
+ - !ruby/object:Gem::Version
55
+ version: '4'
50
56
  - !ruby/object:Gem::Dependency
51
57
  name: coveralls_reborn
52
58
  requirement: !ruby/object:Gem::Requirement
@@ -138,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
144
  - !ruby/object:Gem::Version
139
145
  version: '0'
140
146
  requirements: []
141
- rubygems_version: 3.6.2
147
+ rubygems_version: 3.6.9
142
148
  specification_version: 4
143
149
  summary: a ruby library/gem for interacting with .docx files
144
150
  test_files: []