docxify 0.1.4 → 0.1.6

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: 9feb2e005b3722bb91013f2b319a93da1f7ee49cbce3d28491dc279f1a06776a
4
- data.tar.gz: 792b462f78fb7c03dc73f12ef9c9ab9359e55ab09d06a3cbcf10bd65b332cac9
3
+ metadata.gz: '078327d60105c81b5d2408dc41a12f8938fc99ef39fc813e5313913b4fb85fe8'
4
+ data.tar.gz: 8a96ec54548b34768e3480db12349ed9301c5fbc0f3f5b5f470b2788805541a0
5
5
  SHA512:
6
- metadata.gz: fe9457df0501983598674783c781ebf2cc8b964e540aadc90645d8a1132a62ed0a28c2cbec56931d069b2435cb5e6419cca4a7e4232afb22f0b4a08bac2687ee
7
- data.tar.gz: 0a8d8fb56b6f88350885cb0afadf8100fa31b682c3bef5c1cdba90ce0c039fdb9fc2f00aa3024723c9add5bb7cc97b288378def2f0ccf4ab85287f72d4f65408
6
+ metadata.gz: 7891e352135d11bba98851c99733afece051a37fb283d2f576179dfd66a1a0da6e8656cd0b2d1885389b448baff183194cb0ce3e0599d468330f5b6981f4619f
7
+ data.tar.gz: 28098adcc6b17ca39f67c15a5dacfe63c5d1d453bd19da781b0124b9398fb534fdeae8f78597c36372aa5f2b4103e961553474c9ea14783be9a86d7161a27400
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.6
4
+
5
+ Bugfix:
6
+
7
+ - Stop additional page being added after content. Add known issue.
8
+
9
+ ## 0.1.5
10
+
11
+ Bugfix:
12
+
13
+ - Should insert image with correct aspect ratio if only one dimension is specified
14
+
3
15
  ## 0.1.4
4
16
 
5
17
  Bugfix:
data/README.md CHANGED
@@ -90,6 +90,10 @@ The main object created by users is a `DocXify::Document`. This builds up a `@co
90
90
 
91
91
  The `render` method on a `DocXify::Document` will generate a complete `document.xml` (Word terminology not a Ruby method) by creating a template and iterating each `@content` item. It will then create a `DocXify::Container` with that `document.xml` to generate a complete Zipped DocX file, and call it's `render` method to generate an in-memory file. This is then either returned to the `render` caller, or if a file path was passed as the first attribute, then it writes it out.
92
92
 
93
+ ### Known issues
94
+
95
+ The only known issue is that it doesn't like mixing and matching page orientations. If you start a document as portrait or landscape, it's fine, but it really doesn't like a single page being in a different orientation.
96
+
93
97
  ## Contributing
94
98
 
95
99
  Bug reports and pull requests are welcome on GitHub at <https://github.com/foundercatalyst/docxify>.
@@ -8,7 +8,7 @@ module DocXify
8
8
  @relationships = []
9
9
  @width = options[:width] || A4_PORTRAIT_WIDTH
10
10
  @height = options[:height] || A4_PORTRAIT_HEIGHT
11
- @orientation = options[:orientation] || :portrait
11
+ @orientation = options[:orientation]
12
12
  @font = options[:font] || "Times New Roman"
13
13
  @size = options[:size] || 12
14
14
  @color = options[:color] || 12
@@ -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,16 +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
- elsif contains_jpeg_image?(file_path_or_data)
26
- @data = file_path_or_data
27
- @filename = "#{Digest::SHA1.hexdigest(@data)}.jpg"
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"
28
28
  else
29
29
  raise ArgumentError.new("Unsupported file type - images must be PNG or JPEG")
30
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
@@ -12,7 +12,7 @@ module DocXify
12
12
  @margins = @document.margins
13
13
  @width = options[:width] || @document&.width || DocXify::A4_PORTRAIT_WIDTH
14
14
  @height = options[:height] || @document&.height || DocXify::A4_PORTRAIT_HEIGHT
15
- @orientation = options[:orientation] || :portrait
15
+ @orientation = options[:orientation]
16
16
  end
17
17
 
18
18
  # Don't consider this part of the public API, they're used by Document if it's been created
@@ -26,16 +26,12 @@ module DocXify
26
26
 
27
27
  def to_s(_container = nil)
28
28
  <<~XML
29
- <w:p>
30
- <w:pPr>
31
- <w:sectPr>
32
- <w:pgSz w:w="#{@width}" w:h="#{@height}" w:orient="#{@orientation}"/>
33
- <w:pgMar w:bottom="#{DocXify.cm2dxa @margins[:bottom]}" w:footer="708" w:gutter="0" w:header="708" w:left="#{DocXify.cm2dxa @margins[:left]}" w:right="#{DocXify.cm2dxa @margins[:right]}" w:top="#{DocXify.cm2dxa @margins[:top]}"/>
34
- <w:cols w:space="708"/>
35
- <w:docGrid w:linePitch="360"/>
36
- </w:sectPr>
37
- </w:pPr>
38
- </w:p>
29
+ <w:sectPr>
30
+ <w:pgSz w:w="#{@width}" w:h="#{@height}" #{'w:orient="portrait}"' if @orientation.to_s == "portrait"} #{'w:orient="landscape}"' if @orientation.to_s == "landscape"} />
31
+ <w:pgMar w:bottom="#{DocXify.cm2dxa @margins[:bottom]}" w:footer="708" w:gutter="0" w:header="708" w:left="#{DocXify.cm2dxa @margins[:left]}" w:right="#{DocXify.cm2dxa @margins[:right]}" w:top="#{DocXify.cm2dxa @margins[:top]}"/>
32
+ <w:cols w:space="708"/>
33
+ <w:docGrid w:linePitch="360"/>
34
+ </w:sectPr>
39
35
  XML
40
36
  end
41
37
  end
@@ -1,3 +1,3 @@
1
1
  module DocXify
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.1.6".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.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-09-24 00:00:00.000000000 Z
12
+ date: 2025-03-14 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
@@ -76,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
90
  - !ruby/object:Gem::Version
77
91
  version: '0'
78
92
  requirements: []
79
- rubygems_version: 3.5.17
93
+ rubygems_version: 3.5.21
80
94
  signing_key:
81
95
  specification_version: 4
82
96
  summary: DocXify is a gem to help you generate Word documents from Ruby.