standard-procedure-consolidate 0.4.0 → 0.4.1

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: 39e8b33a8f43ddb4a3bff6ccfb91ee9608d741dc9dff3759ea7c45b1c3cf3d3c
4
- data.tar.gz: 71d357d9e60a98f199c7d67ab3f6a0b5ee8999218162fabf43a4fc4283f04a85
3
+ metadata.gz: 0ffce925315399bd4432936d929e995114acc2dea081f3835eb437fe2787f612
4
+ data.tar.gz: b64ae5181ae92d5e66be79e5861787c3355fe08870dbb4ee3ab8355ef4ce149d
5
5
  SHA512:
6
- metadata.gz: e68a557b00ecb43feb93cdc9a5c9a4c09edd93f8421206be3372e617809bc9ce01cb9ad4928e6f97f49b6db64fd9a329dd2ff7360d5d7b618ce455d0f080c6b1
7
- data.tar.gz: 94417403770d855c0df0d1927b3de00235a668503790e06388de83cadb3b3d2b533f394fab3ddcda5ace164bbe7394810c8ad6b00092eb553552f74fabaa2e5e
6
+ metadata.gz: e56547c32223cf66f807c804cdfff2897f63887729dcf1ff80d51c35a0615115f47b16347b582d58a6ae128c3ecad91a67ca128e0d7c89b6e55a3e88b2d5a6c9
7
+ data.tar.gz: 4b351ad3a367dd4382abc18e18fbc978095fec92aa8b258a90feb82f2e0a65ffbcca26a8177383d75fab07d711a170b10b541e48c195c4b8b7db0eea2cfd1b26
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # [0.4.1] - 2024-12-18
2
+
3
+ Replace image merge fields with blanks if the image data is not provided
4
+
1
5
  # [0.4.0] - 2024-12-16
2
6
 
3
7
  Image embedding works
@@ -0,0 +1 @@
1
+ dfd2ec36154a632f86dd8f99a2b85c59ed6048dbb6b8100f84645ea1cf49e3e77ad73b3367ef89d46e055c860f1b1e82c5b0d0d37c969a19c2644a3e42ebbe21
@@ -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#{relation_number_for(field_name)}"
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].media_path}" if verbose
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
- puts "... substituting '#{field_name}' with '<#{relation_id_for(field_name)}/>'" if verbose
249
- 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
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Consolidate
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahoul Baruah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-16 00:00:00.000000000 Z
11
+ date: 2024-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -65,6 +65,7 @@ files:
65
65
  - checksums/standard-procedure-consolidate-0.3.1.gem.sha512
66
66
  - checksums/standard-procedure-consolidate-0.3.9.gem.sha512
67
67
  - checksums/standard-procedure-consolidate-0.4.0.gem.sha512
68
+ - checksums/standard-procedure-consolidate-0.4.1.gem.sha512
68
69
  - exe/consolidate
69
70
  - exe/examine
70
71
  - lib/consolidate.rb