docxify 0.1.3 → 0.1.5

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: 7440bb498b7d16a2e1abb5a6a65edfa8cafe69f9e9edc5175431a685becec44e
4
- data.tar.gz: 0f099f0d7213de1d3c9d3d32e18d150b5cf119b6b2be53b9b4d74dd21fe90a53
3
+ metadata.gz: 71db0768a21fe9c99eaca1fe8835db8f0619530f3b111fc767afd1bbd15c5da5
4
+ data.tar.gz: 46507a64f582f7f6486556ab68e26baf93a4d3c1353293b0c1aa9068cbe9a0cf
5
5
  SHA512:
6
- metadata.gz: f7761058786959073a9cf63d72206f6861a9afcc65df64e209e1ecd365b9ca47f99bbd7c11435f1d2688af8dc4f4734ff56cf4249767d1e3ab0c829f3d9aea1f
7
- data.tar.gz: c4fefd656f6d9a3bf3c87ffc21c94f8c85e41700e880588bd16d266eeb734b98a874e5805a85a767b06596f2a6bdeff17e71c00d9a3d05f43bdbeee6c87ef6b1
6
+ metadata.gz: eaecad61bffa383575bc36536ac8c39d66e745e22fd2b26f509f39325b1faeecb66904ac9184b179e3e27883065ebd7dfe982667bb68c9b6cbdb7dfacb866055
7
+ data.tar.gz: 1bd65897a04c0a22ff34b7d1224c8d39a1421219d4d6e4abf7e187bd14764e493c72fb205a7b4f33699866d1f018d5c420989123b6a05542e57c962acb83721b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.5
4
+
5
+ Bugfix:
6
+
7
+ - Should insert image with correct aspect ratio if only one dimension is specified
8
+
9
+ ## 0.1.4
10
+
11
+ Bugfix:
12
+
13
+ - Removed accidentally left debug statement
14
+
3
15
  ## 0.1.3
4
16
 
5
17
  Bugfix:
@@ -7,7 +7,7 @@ module DocXify
7
7
  JPEG_START = "\xFF\xD8".b.freeze
8
8
  JPEG_END = "\xFF\xD9".b.freeze
9
9
 
10
- attr_accessor :data, :filename
10
+ attr_accessor :data, :filename, :width, :height
11
11
 
12
12
  def initialize(file_path_or_data)
13
13
  super()
@@ -15,18 +15,16 @@ module DocXify
15
15
  end
16
16
 
17
17
  def load_file_data(file_path_or_data)
18
- if ::File.exist?(file_path_or_data)
18
+ if (::File.exist?(file_path_or_data) rescue false)
19
19
  file_path_or_data = ::File.read(file_path_or_data, mode: "rb")
20
20
  end
21
21
 
22
- if contains_png_image?(file_path_or_data)
23
- @data = file_path_or_data
24
- @filename = "#{Digest::SHA1.hexdigest(@data)}.png"
25
- puts "Contains PNG image #{@filename}"
26
- elsif contains_jpeg_image?(file_path_or_data)
27
- @data = file_path_or_data
28
- @filename = "#{Digest::SHA1.hexdigest(@data)}.jpg"
29
- puts "Contains JPEG image #{@filename}"
22
+ @data = file_path_or_data
23
+
24
+ if contains_png_image?(data)
25
+ @filename = "#{Digest::SHA1.hexdigest(data)}.png"
26
+ elsif contains_jpeg_image?(data)
27
+ @filename = "#{Digest::SHA1.hexdigest(data)}.jpg"
30
28
  else
31
29
  raise ArgumentError.new("Unsupported file type - images must be PNG or JPEG")
32
30
  end
@@ -1,3 +1,5 @@
1
+ require "image_size"
2
+
1
3
  module DocXify
2
4
  module Element
3
5
  class Image < Base
@@ -9,8 +11,25 @@ module DocXify
9
11
 
10
12
  @align = options[:align] || :left
11
13
  @after = options[:after]
12
- @height_cm = options[:height_cm] || 5
13
- @width_cm = options[:width_cm] || 5
14
+ @height_cm = options[:height_cm]
15
+ @width_cm = options[:width_cm]
16
+
17
+ image_size = ImageSize.new(StringIO.new(file.data))
18
+
19
+ if @height_cm.nil? || @width_cm.nil?
20
+ @width = image_size.width
21
+ @height = image_size.height
22
+ end
23
+
24
+ if @height_cm.nil? && @width_cm.nil?
25
+ @height_cm = 5
26
+ end
27
+
28
+ if @height_cm.nil?
29
+ @height_cm = @width_cm * image_size.height / image_size.width
30
+ elsif @width_cm.nil?
31
+ @width_cm = @height_cm * image_size.width / image_size.height
32
+ end
14
33
  end
15
34
 
16
35
  def id
@@ -1,3 +1,3 @@
1
1
  module DocXify
2
- VERSION = "0.1.3".freeze
2
+ VERSION = "0.1.5".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docxify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
@@ -11,6 +11,20 @@ bindir: exe
11
11
  cert_chain: []
12
12
  date: 2024-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: image_size
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: rubyzip
16
30
  requirement: !ruby/object:Gem::Requirement