standard-procedure-consolidate 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -6
- data/checksums/standard-procedure-consolidate-0.1.3.gem.sha512 +1 -0
- data/lib/consolidate/docx/merge.rb +25 -16
- data/lib/consolidate/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2d1794f2a364e867d285325c3a0dd9b5c6b4716145d5eaf964c91c44e937e5c
|
4
|
+
data.tar.gz: 6622d19bc3de12fe8d77775b579c1531a057a27bacf227b0b119a252e7fd0003
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb6944c739e5d772a45076b86f5c08d299913575027845ba505aa76b4ade18e3ecb47efe77f4499ac2a01f8782fcbf797b7dde9d00fb479716ac0b927288c9b4
|
7
|
+
data.tar.gz: b9c10360e43007c6cd523ad238664786f2aa0884e524349d451989646e05f3f59569821e7361a8f4c553dad182ca61588629d108359b08953287bddf62f8533c
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,26 @@
|
|
1
|
+
## [0.1.3] - 2023-09-07
|
1
2
|
|
2
|
-
|
3
|
+
Customer had an issue where some fields were not merging correctly
|
3
4
|
|
4
|
-
|
5
|
+
- Altered the code so it tries to perform the substitution in all .xml files that aren't obviously configuration data
|
6
|
+
- Added verbose option to show what the code was doing
|
7
|
+
- Added a list of files to `examine`
|
8
|
+
- Still no tests for the header/footer support
|
5
9
|
|
6
|
-
-
|
10
|
+
## [0.1.2] - 2023-08-23
|
11
|
+
|
12
|
+
- Added untested support for headers and footers
|
13
|
+
- this work was done in a rush to deal with a customer requirement - tests to come soon
|
7
14
|
|
8
15
|
## [0.1.1] - 2023-08-02
|
9
16
|
|
10
17
|
- Added `examine` to list the merge fields within a document
|
11
18
|
|
12
|
-
##
|
19
|
+
## [0.1.0] - 2023-07-25
|
20
|
+
|
21
|
+
- Initial release
|
22
|
+
|
23
|
+
## [Unreleased]
|
24
|
+
|
25
|
+
|
13
26
|
|
14
|
-
- Added untested support for headers and footers
|
15
|
-
- this work was done in a rush to deal with a customer requirement - tests to come soon
|
@@ -0,0 +1 @@
|
|
1
|
+
fcf685ae67c99908b9d67a57e9bd4bfe6dc8f61c3e421e167d0c9912ab6ac32fd4ad9a273cbbee47e9157cafb311aaecb8db0995eb227aa0afe0bdcc3bc01ee3
|
@@ -6,12 +6,14 @@ require "nokogiri"
|
|
6
6
|
module Consolidate
|
7
7
|
module Docx
|
8
8
|
class Merge
|
9
|
-
def self.open(path,
|
10
|
-
new(path,
|
9
|
+
def self.open(path, verbose: false, &block)
|
10
|
+
new(path, verbose: verbose, &block)
|
11
|
+
path
|
11
12
|
end
|
12
13
|
|
13
14
|
def examine
|
14
|
-
|
15
|
+
puts "Documents: #{extract_document_names}"
|
16
|
+
puts "Merge fields: #{extract_field_names}"
|
15
17
|
end
|
16
18
|
|
17
19
|
def data fields = {}
|
@@ -38,37 +40,46 @@ module Consolidate
|
|
38
40
|
|
39
41
|
protected
|
40
42
|
|
43
|
+
attr_reader :verbose
|
41
44
|
attr_reader :zip
|
42
45
|
attr_reader :xml
|
43
46
|
attr_reader :documents
|
44
47
|
attr_accessor :output
|
45
48
|
|
46
|
-
|
49
|
+
EXCLUSIONS = %w{_rels/.rels [Content_Types].xml word/_rels/document.xml.rels word/theme/theme1.xml word/settings.xml word/_rels/settings.xml.rels word/styles.xml word/webSettings.xml word/fontTable.xml docProps/core.xml docProps/app.xml}
|
50
|
+
|
51
|
+
def initialize(path, verbose: false, &block)
|
47
52
|
raise "No block given" unless block
|
53
|
+
@verbose = verbose
|
48
54
|
@output = {}
|
49
55
|
@documents = {}
|
50
|
-
set_standard_settings if force_settings
|
51
56
|
begin
|
52
57
|
@zip = Zip::File.open(path)
|
53
|
-
|
54
|
-
next
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
@zip.entries.each do |entry|
|
59
|
+
next if EXCLUSIONS.include? entry.name
|
60
|
+
puts "Reading #{entry.name}" if verbose
|
61
|
+
xml = @zip.get_input_stream entry
|
62
|
+
@documents[entry.name] = Nokogiri::XML(xml) { |x| x.noent }
|
58
63
|
end
|
64
|
+
yield self
|
59
65
|
ensure
|
60
66
|
@zip.close
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
70
|
+
def extract_document_names
|
71
|
+
@zip.entries.collect { |entry| entry.name }.join(", ")
|
72
|
+
end
|
73
|
+
|
64
74
|
def extract_field_names
|
65
|
-
(extract_style_one + extract_style_two).uniq
|
75
|
+
(extract_style_one + extract_style_two).uniq.join(", ")
|
66
76
|
end
|
67
77
|
|
68
78
|
def extract_style_one
|
69
79
|
documents.collect do |name, document|
|
70
80
|
(document / "//w:fldSimple").collect do |field|
|
71
81
|
value = field.attributes["instr"].value.strip
|
82
|
+
puts "...found #{value} (v1) in #{name}" if verbose
|
72
83
|
value.include?("MERGEFIELD") ? value.gsub("MERGEFIELD", "").strip : nil
|
73
84
|
end.compact
|
74
85
|
end.flatten
|
@@ -78,6 +89,7 @@ module Consolidate
|
|
78
89
|
documents.collect do |name, document|
|
79
90
|
(document / "//w:instrText").collect do |instr|
|
80
91
|
value = instr.inner_text
|
92
|
+
puts "...found #{value} (v2) in #{name}" if verbose
|
81
93
|
value.include?("MERGEFIELD") ? value.gsub("MERGEFIELD", "").strip : nil
|
82
94
|
end.compact
|
83
95
|
end.flatten
|
@@ -89,6 +101,7 @@ module Consolidate
|
|
89
101
|
if field.attributes["instr"].value =~ /MERGEFIELD (\S+)/
|
90
102
|
text_node = (field / ".//w:t").first
|
91
103
|
next unless text_node
|
104
|
+
puts "...substituting v1 #{field.attributes["instr"]} with #{fields[$1]}" if verbose
|
92
105
|
text_node.inner_html = fields[$1].to_s
|
93
106
|
end
|
94
107
|
end
|
@@ -102,17 +115,13 @@ module Consolidate
|
|
102
115
|
text_node = instr.parent.next_sibling.next_sibling.xpath(".//w:t").first
|
103
116
|
text_node ||= instr.parent.next_sibling.next_sibling.next_sibling.xpath(".//w:t").first
|
104
117
|
next unless text_node
|
118
|
+
puts "...substituting v2 #{instr.inner_text} with #{fields[$1]}" if verbose
|
105
119
|
text_node.inner_html = fields[$1].to_s
|
106
120
|
end
|
107
121
|
end
|
108
122
|
document
|
109
123
|
end
|
110
124
|
|
111
|
-
def set_standard_settings
|
112
|
-
output["word/settings.xml"] = %(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
113
|
-
<w:settings xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main"><w:zoom w:percent="100"/></w:settings>)
|
114
|
-
end
|
115
|
-
|
116
125
|
def close
|
117
126
|
zip.close
|
118
127
|
end
|
data/lib/consolidate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard-procedure-consolidate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahoul Baruah
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- Rakefile
|
58
58
|
- checksums/standard-procedure-consolidate-0.1.0.gem.sha512
|
59
59
|
- checksums/standard-procedure-consolidate-0.1.2.gem.sha512
|
60
|
+
- checksums/standard-procedure-consolidate-0.1.3.gem.sha512
|
60
61
|
- exe/consolidate
|
61
62
|
- lib/consolidate.rb
|
62
63
|
- lib/consolidate/docx/merge.rb
|
@@ -71,7 +72,7 @@ metadata:
|
|
71
72
|
homepage_uri: https://github.com/standard-procedure/standard-procedure-consolidate
|
72
73
|
source_code_uri: https://github.com/standard-procedure/standard-procedure-consolidate
|
73
74
|
changelog_uri: https://github.com/standard-procedure/standard-procedure-consolidate/blob/main/CHANGELOG.md
|
74
|
-
post_install_message:
|
75
|
+
post_install_message:
|
75
76
|
rdoc_options: []
|
76
77
|
require_paths:
|
77
78
|
- lib
|
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
88
|
version: '0'
|
88
89
|
requirements: []
|
89
90
|
rubygems_version: 3.4.10
|
90
|
-
signing_key:
|
91
|
+
signing_key:
|
91
92
|
specification_version: 4
|
92
93
|
summary: Simple ruby mailmerge for Microsoft Word .docx files.
|
93
94
|
test_files: []
|