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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +4 -0
- data/lib/docxify/document.rb +1 -1
- data/lib/docxify/element/file.rb +8 -8
- data/lib/docxify/element/image.rb +21 -2
- data/lib/docxify/element/page_layout.rb +7 -11
- data/lib/docxify/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '078327d60105c81b5d2408dc41a12f8938fc99ef39fc813e5313913b4fb85fe8'
|
4
|
+
data.tar.gz: 8a96ec54548b34768e3480db12349ed9301c5fbc0f3f5b5f470b2788805541a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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>.
|
data/lib/docxify/document.rb
CHANGED
@@ -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]
|
11
|
+
@orientation = options[:orientation]
|
12
12
|
@font = options[:font] || "Times New Roman"
|
13
13
|
@size = options[:size] || 12
|
14
14
|
@color = options[:color] || 12
|
data/lib/docxify/element/file.rb
CHANGED
@@ -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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@filename = "#{Digest::SHA1.hexdigest(
|
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]
|
13
|
-
@width_cm = options[:width_cm]
|
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]
|
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:
|
30
|
-
<w:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
data/lib/docxify/version.rb
CHANGED
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
|
+
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:
|
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.
|
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.
|