standard-procedure-consolidate 0.1.1 → 0.1.3
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 +4 -4
- data/.devcontainer/devcontainer.json +7 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +19 -3
- data/README.md +8 -4
- data/checksums/standard-procedure-consolidate-0.1.2.gem.sha512 +1 -0
- data/checksums/standard-procedure-consolidate-0.1.3.gem.sha512 +1 -0
- data/lib/consolidate/docx/merge.rb +45 -27
- data/lib/consolidate/version.rb +1 -1
- metadata +7 -3
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
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
|
3
|
+
{
|
4
|
+
"name": "Ruby",
|
5
|
+
"image": "mcr.microsoft.com/devcontainers/ruby:1-3.2-bullseye",
|
6
|
+
"postCreateCommand": "bundle install"
|
7
|
+
}
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +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
|
18
|
+
|
19
|
+
## [0.1.0] - 2023-07-25
|
20
|
+
|
21
|
+
- Initial release
|
22
|
+
|
23
|
+
## [Unreleased]
|
24
|
+
|
25
|
+
|
26
|
+
|
data/README.md
CHANGED
@@ -33,13 +33,17 @@ NOTE: The merge fields are case-sensitive - which is why they should be supplied
|
|
33
33
|
|
34
34
|
## Development
|
35
35
|
|
36
|
-
|
36
|
+
The repo contains a .devcontainer folder - this contains instructions for a development container that has everything needed to build the project. Once the container has started, you can use `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
37
|
|
38
|
-
|
38
|
+
`bundle exec rake install` will install the gem on your local machine (obviously not from within the devcontainer though). To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
39
|
|
40
40
|
## Contributing
|
41
41
|
|
42
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/standard-procedure/standard-procedure-consolidate.
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/standard-procedure/standard-procedure-consolidate.
|
43
|
+
|
44
|
+
When adding commit messages, please explain _why_ the change is being made.
|
45
|
+
|
46
|
+
When submitting a pull request, please ensure that there is an RSpec detailing how the feature works and please explain, in the pull request itself, the reasoning behind adding the feature.
|
43
47
|
|
44
48
|
## License
|
45
49
|
|
@@ -47,4 +51,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
47
51
|
|
48
52
|
## Code of Conduct
|
49
53
|
|
50
|
-
Everyone interacting in the Standard::Procedure::Consolidate project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
54
|
+
Everyone interacting in the Standard::Procedure::Consolidate project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/standard-procedure/standard-procedure-consolidate/blob/main/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1 @@
|
|
1
|
+
055a4ccf5326b9f737e0222cecfdbaee34554fc42dcfaf017807e643fdc1ceb06b35329fe6a8ca32805c7ca3adf0c7df39b6bc32766208d69820243cde0a3648
|
@@ -0,0 +1 @@
|
|
1
|
+
fcf685ae67c99908b9d67a57e9bd4bfe6dc8f61c3e421e167d0c9912ab6ac32fd4ad9a273cbbee47e9157cafb311aaecb8db0995eb227aa0afe0bdcc3bc01ee3
|
@@ -6,22 +6,26 @@ 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 = {}
|
18
20
|
fields = fields.transform_keys(&:to_s)
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
@documents.each do |name, document|
|
23
|
+
result = document.dup
|
24
|
+
result = substitute_style_one_with result, fields
|
25
|
+
result = substitute_style_two_with result, fields
|
23
26
|
|
24
|
-
|
27
|
+
@output[name] = result.serialize save_with: 0
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
def write_to path
|
@@ -36,42 +40,59 @@ module Consolidate
|
|
36
40
|
|
37
41
|
protected
|
38
42
|
|
43
|
+
attr_reader :verbose
|
39
44
|
attr_reader :zip
|
40
45
|
attr_reader :xml
|
41
|
-
attr_reader :
|
46
|
+
attr_reader :documents
|
42
47
|
attr_accessor :output
|
43
48
|
|
44
|
-
|
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)
|
45
52
|
raise "No block given" unless block
|
53
|
+
@verbose = verbose
|
46
54
|
@output = {}
|
47
|
-
|
55
|
+
@documents = {}
|
48
56
|
begin
|
49
57
|
@zip = Zip::File.open(path)
|
50
|
-
@
|
51
|
-
|
52
|
-
|
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 }
|
63
|
+
end
|
53
64
|
yield self
|
54
65
|
ensure
|
55
66
|
@zip.close
|
56
67
|
end
|
57
68
|
end
|
58
69
|
|
70
|
+
def extract_document_names
|
71
|
+
@zip.entries.collect { |entry| entry.name }.join(", ")
|
72
|
+
end
|
73
|
+
|
59
74
|
def extract_field_names
|
60
|
-
(extract_style_one + extract_style_two).uniq
|
75
|
+
(extract_style_one + extract_style_two).uniq.join(", ")
|
61
76
|
end
|
62
77
|
|
63
78
|
def extract_style_one
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
79
|
+
documents.collect do |name, document|
|
80
|
+
(document / "//w:fldSimple").collect do |field|
|
81
|
+
value = field.attributes["instr"].value.strip
|
82
|
+
puts "...found #{value} (v1) in #{name}" if verbose
|
83
|
+
value.include?("MERGEFIELD") ? value.gsub("MERGEFIELD", "").strip : nil
|
84
|
+
end.compact
|
85
|
+
end.flatten
|
68
86
|
end
|
69
87
|
|
70
88
|
def extract_style_two
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
89
|
+
documents.collect do |name, document|
|
90
|
+
(document / "//w:instrText").collect do |instr|
|
91
|
+
value = instr.inner_text
|
92
|
+
puts "...found #{value} (v2) in #{name}" if verbose
|
93
|
+
value.include?("MERGEFIELD") ? value.gsub("MERGEFIELD", "").strip : nil
|
94
|
+
end.compact
|
95
|
+
end.flatten
|
75
96
|
end
|
76
97
|
|
77
98
|
def substitute_style_one_with document, fields
|
@@ -80,6 +101,7 @@ module Consolidate
|
|
80
101
|
if field.attributes["instr"].value =~ /MERGEFIELD (\S+)/
|
81
102
|
text_node = (field / ".//w:t").first
|
82
103
|
next unless text_node
|
104
|
+
puts "...substituting v1 #{field.attributes["instr"]} with #{fields[$1]}" if verbose
|
83
105
|
text_node.inner_html = fields[$1].to_s
|
84
106
|
end
|
85
107
|
end
|
@@ -93,17 +115,13 @@ module Consolidate
|
|
93
115
|
text_node = instr.parent.next_sibling.next_sibling.xpath(".//w:t").first
|
94
116
|
text_node ||= instr.parent.next_sibling.next_sibling.next_sibling.xpath(".//w:t").first
|
95
117
|
next unless text_node
|
118
|
+
puts "...substituting v2 #{instr.inner_text} with #{fields[$1]}" if verbose
|
96
119
|
text_node.inner_html = fields[$1].to_s
|
97
120
|
end
|
98
121
|
end
|
99
122
|
document
|
100
123
|
end
|
101
124
|
|
102
|
-
def set_standard_settings
|
103
|
-
output["word/settings.xml"] = %(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
104
|
-
<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>)
|
105
|
-
end
|
106
|
-
|
107
125
|
def close
|
108
126
|
zip.close
|
109
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
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
|
@@ -46,7 +46,9 @@ executables:
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- ".devcontainer/devcontainer.json"
|
49
50
|
- ".rspec"
|
51
|
+
- ".ruby-version"
|
50
52
|
- ".standard.yml"
|
51
53
|
- CHANGELOG.md
|
52
54
|
- CODE_OF_CONDUCT.md
|
@@ -54,6 +56,8 @@ files:
|
|
54
56
|
- README.md
|
55
57
|
- Rakefile
|
56
58
|
- checksums/standard-procedure-consolidate-0.1.0.gem.sha512
|
59
|
+
- checksums/standard-procedure-consolidate-0.1.2.gem.sha512
|
60
|
+
- checksums/standard-procedure-consolidate-0.1.3.gem.sha512
|
57
61
|
- exe/consolidate
|
58
62
|
- lib/consolidate.rb
|
59
63
|
- lib/consolidate/docx/merge.rb
|
@@ -83,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
87
|
- !ruby/object:Gem::Version
|
84
88
|
version: '0'
|
85
89
|
requirements: []
|
86
|
-
rubygems_version: 3.4.
|
90
|
+
rubygems_version: 3.4.10
|
87
91
|
signing_key:
|
88
92
|
specification_version: 4
|
89
93
|
summary: Simple ruby mailmerge for Microsoft Word .docx files.
|