standard-procedure-consolidate 0.4.0 → 0.4.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 +4 -4
- data/.devcontainer/devcontainer.json +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +4 -0
- data/checksums/standard-procedure-consolidate-0.4.1.gem.sha512 +1 -0
- data/checksums/standard-procedure-consolidate-0.4.2.gem.sha512 +1 -0
- data/lib/consolidate/docx/image_reference_node_builder.rb +28 -4
- data/lib/consolidate/docx/merge.rb +15 -5
- data/lib/consolidate/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cbb574bced054ba32f67038b7f91eed28836470eb0d40e7bbbbcaefdca41142
|
4
|
+
data.tar.gz: 64438e3b31ea879c4c10d42afa08873a44528ec89ba60d3e248c07baf1bd028b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947a488ad5d98514589cbaa9495cd7970e7821832a05f74719821d9423785fc9e04f2563b7c4c4c34e5c5c25c32c6a1fd175cbd862e247cdfc2e8612663412b4
|
7
|
+
data.tar.gz: cc6e12303d7abea0be365df9c443d868d18bc658f3696488a6826ce83b93cfd17e588aecc6f3af94a9ac46e9621bc483800effd44e37b550dc752767757fe9fc
|
@@ -2,7 +2,7 @@
|
|
2
2
|
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
|
3
3
|
{
|
4
4
|
"name": "Ruby",
|
5
|
-
"image": "
|
5
|
+
"image": "ghcr.io/rails/devcontainer/images/ruby:3.3.5",
|
6
6
|
"postCreateCommand": "bundle install",
|
7
7
|
"customizations": {
|
8
8
|
"vscode": {
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.5
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
dfd2ec36154a632f86dd8f99a2b85c59ed6048dbb6b8100f84645ea1cf49e3e77ad73b3367ef89d46e055c860f1b1e82c5b0d0d37c969a19c2644a3e42ebbe21
|
@@ -0,0 +1 @@
|
|
1
|
+
391a0d85024adf2a5866f0dabab3d601e6865c482e4fff5e780af0a6dc6ca36aade243a9e97cdb68552b00fce51d763ed94e89a701ce466428a64df9f4d574a0
|
@@ -7,6 +7,9 @@ module Consolidate
|
|
7
7
|
module Docx
|
8
8
|
class ImageReferenceNodeBuilder < Data.define(:field_name, :image, :node_id, :image_number, :document)
|
9
9
|
def call
|
10
|
+
max_width, max_height = max_dimensions_from(document)
|
11
|
+
scaled_width, scaled_height = scale_dimensions(image.width, image.height, max_width, max_height)
|
12
|
+
|
10
13
|
Nokogiri::XML::Node.new("w:drawing", document).tap do |drawing|
|
11
14
|
drawing["xmlns:a"] = "http://schemas.openxmlformats.org/drawingml/2006/main"
|
12
15
|
drawing << Nokogiri::XML::Node.new("wp:inline", document).tap do |inline|
|
@@ -15,8 +18,8 @@ module Consolidate
|
|
15
18
|
inline["distL"] = "0"
|
16
19
|
inline["distR"] = "0"
|
17
20
|
inline << Nokogiri::XML::Node.new("wp:extent", document).tap do |extent|
|
18
|
-
extent["cx"] =
|
19
|
-
extent["cy"] =
|
21
|
+
extent["cx"] = scaled_width
|
22
|
+
extent["cy"] = scaled_height
|
20
23
|
end
|
21
24
|
inline << Nokogiri::XML::Node.new("wp:effectExtent", document).tap do |effect_extent|
|
22
25
|
effect_extent["l"] = "0"
|
@@ -59,8 +62,8 @@ module Consolidate
|
|
59
62
|
off["y"] = "0"
|
60
63
|
end
|
61
64
|
xfrm << Nokogiri::XML::Node.new("a:ext", document).tap do |ext|
|
62
|
-
ext["cx"] =
|
63
|
-
ext["cy"] =
|
65
|
+
ext["cx"] = scaled_width
|
66
|
+
ext["cy"] = scaled_height
|
64
67
|
end
|
65
68
|
end
|
66
69
|
sp_pr << Nokogiri::XML::Node.new("a:prstGeom", document).tap do |prst_geom|
|
@@ -78,11 +81,32 @@ module Consolidate
|
|
78
81
|
DEFAULT_PAGE_WIDTH = 12_240
|
79
82
|
TWENTIETHS_OF_A_POINT_TO_EMU = 635
|
80
83
|
DEFAULT_PAGE_WIDTH_IN_EMU = DEFAULT_PAGE_WIDTH * TWENTIETHS_OF_A_POINT_TO_EMU
|
84
|
+
EMU_PER_PIXEL = 9525
|
85
|
+
DEFAULT_PAGE_HEIGHT = DEFAULT_PAGE_WIDTH * 11 / 8.5 # Assuming standard page ratio
|
86
|
+
DEFAULT_PAGE_HEIGHT_IN_EMU = DEFAULT_PAGE_HEIGHT * TWENTIETHS_OF_A_POINT_TO_EMU
|
81
87
|
|
82
88
|
private def max_width_from document
|
83
89
|
page_width = (document.at_xpath("//w:sectPr/w:pgSz/@w:w")&.value || DEFAULT_PAGE_WIDTH).to_i
|
84
90
|
page_width * TWENTIETHS_OF_A_POINT_TO_EMU
|
85
91
|
end
|
92
|
+
|
93
|
+
private def max_dimensions_from(document)
|
94
|
+
page_width = (document.at_xpath("//w:sectPr/w:pgSz/@w:w")&.value || DEFAULT_PAGE_WIDTH).to_i
|
95
|
+
page_height = (document.at_xpath("//w:sectPr/w:pgSz/@w:h")&.value || DEFAULT_PAGE_HEIGHT).to_i
|
96
|
+
|
97
|
+
width_emu = page_width * TWENTIETHS_OF_A_POINT_TO_EMU
|
98
|
+
height_emu = page_height * TWENTIETHS_OF_A_POINT_TO_EMU
|
99
|
+
|
100
|
+
[width_emu, height_emu]
|
101
|
+
end
|
102
|
+
|
103
|
+
private def scale_dimensions(width, height, max_width, max_height)
|
104
|
+
width_ratio = max_width.to_f / width
|
105
|
+
height_ratio = max_height.to_f / height
|
106
|
+
scale = [width_ratio, height_ratio, 1.0].min # Never scale up
|
107
|
+
|
108
|
+
[(width * scale).to_i, (height * scale).to_i]
|
109
|
+
end
|
86
110
|
end
|
87
111
|
end
|
88
112
|
end
|
@@ -70,6 +70,7 @@ module Consolidate
|
|
70
70
|
@output[contents_xml] = @contents_xml.serialize save_with: 0
|
71
71
|
|
72
72
|
@images.each do |field_name, image|
|
73
|
+
next if image.nil?
|
73
74
|
puts "... writing image #{field_name} to #{image.storage_path}" if verbose
|
74
75
|
out.get_output_stream(image.storage_path) { |o| o.write image.contents }
|
75
76
|
end
|
@@ -120,7 +121,7 @@ module Consolidate
|
|
120
121
|
def relation_number_for(field_name) = @mapping.keys.index(field_name) + 1000
|
121
122
|
|
122
123
|
# Identifier to use when linking a merge field to the actual image file contents
|
123
|
-
def relation_id_for(field_name) = "rId#{
|
124
|
+
def relation_id_for(field_name) = "rId#{field_name}"
|
124
125
|
|
125
126
|
# Empty elations document for documents that do not already have one
|
126
127
|
def default_relations_document = %(<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>)
|
@@ -156,8 +157,8 @@ module Consolidate
|
|
156
157
|
# Build a mapping of image paths to the image data so that the image data can be stored in the output docx
|
157
158
|
def load_images
|
158
159
|
image_field_names.each_with_object({}) do |field_name, result|
|
159
|
-
result[field_name] = Consolidate::Docx::Image.new(@mapping[field_name])
|
160
|
-
puts "... #{field_name} => #{result[field_name]
|
160
|
+
result[field_name] = @mapping[field_name].nil? ? nil : Consolidate::Docx::Image.new(@mapping[field_name])
|
161
|
+
puts "... #{field_name} => #{result[field_name]&.media_path}" if verbose
|
161
162
|
end
|
162
163
|
end
|
163
164
|
|
@@ -166,6 +167,8 @@ module Consolidate
|
|
166
167
|
@relations.each do |name, xml|
|
167
168
|
puts "... linking images in #{name}" if verbose
|
168
169
|
images.each do |field_name, image|
|
170
|
+
# Has an actual image file been supplied?
|
171
|
+
next if image.nil?
|
169
172
|
# Is this image already referenced in this relationship document?
|
170
173
|
next unless xml.at_xpath("//Relationship[@Target=\"#{image.media_path}\"]").nil?
|
171
174
|
puts "... #{relation_id_for(field_name)} => #{image.media_path}" if verbose
|
@@ -245,8 +248,15 @@ module Consolidate
|
|
245
248
|
field_name = piece.strip
|
246
249
|
if field_names.include? field_name
|
247
250
|
image = @images[field_name]
|
248
|
-
|
249
|
-
|
251
|
+
# if no image was provided then insert blank text
|
252
|
+
# otherwise insert a w:drawing node that references the image contents
|
253
|
+
if image.nil?
|
254
|
+
puts "... substituting '#{field_name}' with blank as no image was provided" if verbose
|
255
|
+
Nokogiri::XML::Node.new("w:t", document) { |t| t.content = "" }
|
256
|
+
else
|
257
|
+
puts "... substituting '#{field_name}' with '<#{relation_id_for(field_name)}/>'" if verbose
|
258
|
+
ImageReferenceNodeBuilder.new(field_name: field_name, image: image, node_id: relation_id_for(field_name), image_number: relation_number_for(field_name), document: document).call
|
259
|
+
end
|
250
260
|
else
|
251
261
|
Nokogiri::XML::Node.new("w:t", document) { |t| t.content = piece }
|
252
262
|
end
|
data/lib/consolidate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard-procedure-consolidate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahoul Baruah
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-20 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rubyzip
|
@@ -65,6 +64,8 @@ files:
|
|
65
64
|
- checksums/standard-procedure-consolidate-0.3.1.gem.sha512
|
66
65
|
- checksums/standard-procedure-consolidate-0.3.9.gem.sha512
|
67
66
|
- checksums/standard-procedure-consolidate-0.4.0.gem.sha512
|
67
|
+
- checksums/standard-procedure-consolidate-0.4.1.gem.sha512
|
68
|
+
- checksums/standard-procedure-consolidate-0.4.2.gem.sha512
|
68
69
|
- exe/consolidate
|
69
70
|
- exe/examine
|
70
71
|
- lib/consolidate.rb
|
@@ -83,7 +84,6 @@ metadata:
|
|
83
84
|
homepage_uri: https://github.com/standard-procedure/standard-procedure-consolidate
|
84
85
|
source_code_uri: https://github.com/standard-procedure/standard-procedure-consolidate
|
85
86
|
changelog_uri: https://github.com/standard-procedure/standard-procedure-consolidate/blob/main/CHANGELOG.md
|
86
|
-
post_install_message:
|
87
87
|
rdoc_options: []
|
88
88
|
require_paths:
|
89
89
|
- lib
|
@@ -98,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
102
|
-
signing_key:
|
101
|
+
rubygems_version: 3.6.2
|
103
102
|
specification_version: 4
|
104
103
|
summary: Simple ruby mailmerge for Microsoft Word .docx files.
|
105
104
|
test_files: []
|