docxify 0.1.1 → 0.1.3
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 +3 -3
- data/lib/docxify/document.rb +1 -1
- data/lib/docxify/element/file.rb +6 -4
- data/lib/docxify/element/image.rb +8 -10
- data/lib/docxify/element/paragraph.rb +6 -4
- data/lib/docxify/version.rb +1 -1
- data/lib/docxify.rb +8 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7440bb498b7d16a2e1abb5a6a65edfa8cafe69f9e9edc5175431a685becec44e
|
4
|
+
data.tar.gz: 0f099f0d7213de1d3c9d3d32e18d150b5cf119b6b2be53b9b4d74dd21fe90a53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7761058786959073a9cf63d72206f6861a9afcc65df64e209e1ecd365b9ca47f99bbd7c11435f1d2688af8dc4f4734ff56cf4249767d1e3ab0c829f3d9aea1f
|
7
|
+
data.tar.gz: c4fefd656f6d9a3bf3c87ffc21c94f8c85e41700e880588bd16d266eeb734b98a874e5805a85a767b06596f2a6bdeff17e71c00d9a3d05f43bdbeee6c87ef6b1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.1.3
|
4
|
+
|
5
|
+
Bugfix:
|
6
|
+
|
7
|
+
- Files that contain a PNG but weren't named ending in .png (e.g. a Tempfile in Ruby) were causing corrupted Docx files (which Word could auto-recover)
|
8
|
+
|
9
|
+
## 0.1.2
|
10
|
+
|
11
|
+
Features:
|
12
|
+
|
13
|
+
- Add 'after' to images and paragraphs to adjust spacing after those elements
|
14
|
+
|
3
15
|
## 0.1.1
|
4
16
|
|
5
17
|
Features:
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ gem install docxify
|
|
23
23
|
|
24
24
|
@docx.default_styling font: "Serif font here", size: 14, color: "#040404"
|
25
25
|
|
26
|
-
@docx.add_paragraph "Title", font: "Something", size: 18, color: "#00000"
|
26
|
+
@docx.add_paragraph "Title", font: "Something", size: 18, color: "#00000", after: 18
|
27
27
|
@docx.add_paragraph "Body copy"
|
28
28
|
@docx.add_paragraph "This is <b>bold</b>, <i>Italic</i> and <u>Underlined</u>."
|
29
29
|
@docx.add_paragraph "Text can also contain <a href='foo'>Links</a>."
|
@@ -37,7 +37,7 @@ gem install docxify
|
|
37
37
|
|
38
38
|
@docx.add_divider
|
39
39
|
|
40
|
-
@docx.add_image "file_path or data", align: :right, height_cm: 2, width_cm: 4
|
40
|
+
@docx.add_image "file_path or data", align: :right, height_cm: 2, width_cm: 4, after: 18
|
41
41
|
|
42
42
|
@docx.add_page_break
|
43
43
|
|
@@ -92,4 +92,4 @@ The `render` method on a `DocXify::Document` will generate a complete `document.
|
|
92
92
|
|
93
93
|
## Contributing
|
94
94
|
|
95
|
-
Bug reports and pull requests are welcome on GitHub at <https://github.com/
|
95
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/foundercatalyst/docxify>.
|
data/lib/docxify/document.rb
CHANGED
@@ -46,7 +46,7 @@ module DocXify
|
|
46
46
|
def build_xml(container)
|
47
47
|
xml = <<~XML
|
48
48
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
49
|
-
<w:document mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
|
49
|
+
<w:document mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh w16du wp14" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16du="http://schemas.microsoft.com/office/word/2023/wordml/word16du" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
|
50
50
|
<w:body>
|
51
51
|
XML
|
52
52
|
|
data/lib/docxify/element/file.rb
CHANGED
@@ -15,16 +15,18 @@ 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)
|
19
|
+
file_path_or_data = ::File.read(file_path_or_data, mode: "rb")
|
20
|
+
end
|
21
|
+
|
18
22
|
if contains_png_image?(file_path_or_data)
|
19
23
|
@data = file_path_or_data
|
20
24
|
@filename = "#{Digest::SHA1.hexdigest(@data)}.png"
|
25
|
+
puts "Contains PNG image #{@filename}"
|
21
26
|
elsif contains_jpeg_image?(file_path_or_data)
|
22
27
|
@data = file_path_or_data
|
23
28
|
@filename = "#{Digest::SHA1.hexdigest(@data)}.jpg"
|
24
|
-
|
25
|
-
@filename = ::File.basename(file_path_or_data)
|
26
|
-
@data = ::File.read(file_path_or_data, mode: "rb")
|
27
|
-
raise ArgumentError.new("Unsupported file type - images must be PNG or JPEG") unless contains_png_image?(@data) || contains_jpeg_image?(@data)
|
29
|
+
puts "Contains JPEG image #{@filename}"
|
28
30
|
else
|
29
31
|
raise ArgumentError.new("Unsupported file type - images must be PNG or JPEG")
|
30
32
|
end
|
@@ -8,6 +8,7 @@ module DocXify
|
|
8
8
|
@file = file
|
9
9
|
|
10
10
|
@align = options[:align] || :left
|
11
|
+
@after = options[:after]
|
11
12
|
@height_cm = options[:height_cm] || 5
|
12
13
|
@width_cm = options[:width_cm] || 5
|
13
14
|
end
|
@@ -19,20 +20,17 @@ module DocXify
|
|
19
20
|
def to_s(_container = nil)
|
20
21
|
xml = "<w:p>"
|
21
22
|
|
23
|
+
xml << "<w:pPr>"
|
22
24
|
if @align == :right
|
23
|
-
xml <<
|
24
|
-
<w:pPr>
|
25
|
-
<w:jc w:val="right"/>
|
26
|
-
</w:pPr>
|
27
|
-
XML
|
25
|
+
xml << "<w:jc w:val=\"right\"/>"
|
28
26
|
elsif @align == :center
|
29
|
-
xml <<
|
30
|
-
<w:pPr>
|
31
|
-
<w:jc w:val="center"/>
|
32
|
-
</w:pPr>
|
33
|
-
XML
|
27
|
+
xml << "<w:jc w:val=\"center\"/>"
|
34
28
|
end
|
35
29
|
|
30
|
+
xml << "<w:spacing w:after=\"#{DocXify.pt2spacing @after}\"/>" if @after
|
31
|
+
|
32
|
+
xml << "</w:pPr>"
|
33
|
+
|
36
34
|
xml << <<~XML
|
37
35
|
<w:r>
|
38
36
|
<w:rPr>
|
@@ -14,6 +14,7 @@ module DocXify
|
|
14
14
|
@background = options[:background] if options[:background]
|
15
15
|
@background ||= @document&.background if @document&.background
|
16
16
|
@align = options[:align] || :left
|
17
|
+
@after = options[:after]
|
17
18
|
@inline_styling = options.key?(:inline_styling) ? options[:inline_styling] : true
|
18
19
|
@tab_stops_cm = options[:tab_stops_cm] || []
|
19
20
|
@hanging_cm = options[:hanging_cm] || 0
|
@@ -21,15 +22,16 @@ module DocXify
|
|
21
22
|
|
22
23
|
def to_s(_container = nil)
|
23
24
|
nodes = if @inline_styling
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
parse_simple_html(@text)
|
26
|
+
else
|
27
|
+
[@text.gsub("<", "<").gsub(">", ">")]
|
28
|
+
end
|
28
29
|
|
29
30
|
xml = "<w:p>"
|
30
31
|
|
31
32
|
xml << "<w:pPr>"
|
32
33
|
xml << "<w:jc w:val=\"#{@align}\"/>" if @align != :left
|
34
|
+
xml << "<w:spacing w:after=\"#{DocXify.pt2spacing @after}\"/>" if @after
|
33
35
|
|
34
36
|
if tab_stops_cm.any?
|
35
37
|
xml << "<w:tabs>"
|
data/lib/docxify/version.rb
CHANGED
data/lib/docxify.rb
CHANGED
@@ -47,6 +47,14 @@ module DocXify
|
|
47
47
|
(value * 2).to_i
|
48
48
|
end
|
49
49
|
|
50
|
+
# Used for spacing
|
51
|
+
def self.pt2spacing(value)
|
52
|
+
value = value.to_f
|
53
|
+
raise ArgumentError.new("Value must be greater than or equal to 0") if value.negative?
|
54
|
+
|
55
|
+
(value * 20).to_i
|
56
|
+
end
|
57
|
+
|
50
58
|
# Used for image sizes
|
51
59
|
def self.cm2emu(value)
|
52
60
|
value = value.to_f
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
|
+
- FounderCatalyst Ltd
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2024-
|
12
|
+
date: 2024-09-24 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rubyzip
|
@@ -27,7 +28,7 @@ dependencies:
|
|
27
28
|
description: Using a relatively simple DSL, you can generate Word DocX documents from
|
28
29
|
Ruby.
|
29
30
|
email:
|
30
|
-
- andy@
|
31
|
+
- andy@foundercatalyst.com
|
31
32
|
executables: []
|
32
33
|
extensions: []
|
33
34
|
extra_rdoc_files: []
|