docxify 0.1.8 → 0.1.10
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/.ruby-version +1 -0
- data/CHANGELOG.md +19 -0
- data/README.md +2 -2
- data/lib/docxify/container.rb +22 -28
- data/lib/docxify/document.rb +2 -2
- data/lib/docxify/element/page_layout.rb +1 -1
- data/lib/docxify/version.rb +1 -1
- data/lib/docxify.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 468ed63c77e6e9759f3310c7b3a45dbfb45437529d39193d4b138998f5ad065a
|
|
4
|
+
data.tar.gz: f59112b36b5d2db86eff32e74dd7184cace6fa40da156bba18eda6871914c9e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9e3f0ad21d53586647982b41dd08ba72f667121ff39b2cce7c47cf1540b3e7a48e1456fbb621ecef0b96aae825d7b8ec2b4899898fd42381a9211b540335d58
|
|
7
|
+
data.tar.gz: 3ea81df4409e565b5e3bfdd6247b5f82296e9bf2334e8bad85de94f4d070754488bf47e7bcb2e6fa395a753622e14daa5d658355183c8d4a67b19063e8161e35
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.1.10
|
|
4
|
+
|
|
5
|
+
Bugfix:
|
|
6
|
+
|
|
7
|
+
- `A4_PORTRAIT_HEIGHT` (and so `A4_LANDSCAPE_WIDTH`) was 15840 twips, which is US Letter's 11 inches; it is now A4's 16838, so documents using the default page size come out on A4
|
|
8
|
+
- `w:orient` was written as `"portrait}"` / `"landscape}"` (stray brace), and the `orientation:` passed to `Document.new` was never written at all
|
|
9
|
+
- `Document#height` reader added, so `add_page_layout` without an explicit `height:` no longer raises `NoMethodError`
|
|
10
|
+
- README showed `page_width:`/`page_height:` (ignored; the options are `width:`/`height:`) and `page_layout` instead of `add_page_layout`
|
|
11
|
+
|
|
12
|
+
## 0.1.9
|
|
13
|
+
|
|
14
|
+
Security:
|
|
15
|
+
|
|
16
|
+
- Require rubyzip 3.6+ (`~> 3.6`), fixing CVE-2026-85396 (path traversal in `Zip::Entry#extract` before rubyzip 3.4.0)
|
|
17
|
+
|
|
18
|
+
Bugfix:
|
|
19
|
+
|
|
20
|
+
- Entry sizes are now declared up front when writing the docx package, so rubyzip 3 no longer adds ZIP64 headers (version needed to extract 4.5) that OPC readers such as Word and Google Docs reject
|
|
21
|
+
|
|
3
22
|
## 0.1.8
|
|
4
23
|
|
|
5
24
|
Bugfix:
|
data/README.md
CHANGED
|
@@ -19,7 +19,7 @@ gem install docxify
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
21
|
```ruby
|
|
22
|
-
@docx = DocXify::Document.new(
|
|
22
|
+
@docx = DocXify::Document.new(width: DocXify::A4_PORTRAIT_WIDTH, height: DocXify::A4_PORTRAIT_HEIGHT)
|
|
23
23
|
|
|
24
24
|
@docx.default_styling font: "Serif font here", size: 14, color: "#040404"
|
|
25
25
|
|
|
@@ -41,7 +41,7 @@ gem install docxify
|
|
|
41
41
|
|
|
42
42
|
@docx.add_page_break
|
|
43
43
|
|
|
44
|
-
@docx.
|
|
44
|
+
@docx.add_page_layout width: DocXify::A4_PORTRAIT_HEIGHT, height: DocXify::A4_PORTRAIT_WIDTH, orientation: :landscape
|
|
45
45
|
|
|
46
46
|
rows = []
|
|
47
47
|
rows << [
|
data/lib/docxify/container.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "tempfile"
|
|
1
2
|
require "zip"
|
|
2
3
|
|
|
3
4
|
module DocXify
|
|
@@ -12,37 +13,19 @@ module DocXify
|
|
|
12
13
|
temp_file = Tempfile.new("docxify.zip")
|
|
13
14
|
|
|
14
15
|
Zip::OutputStream.open(temp_file) do |zip|
|
|
15
|
-
zip
|
|
16
|
-
zip.
|
|
17
|
-
|
|
18
|
-
zip
|
|
19
|
-
zip.
|
|
20
|
-
|
|
21
|
-
zip
|
|
22
|
-
zip.
|
|
23
|
-
|
|
24
|
-
zip.put_next_entry "word/fontTable.xml"
|
|
25
|
-
zip.write DocXify::Template.font_table
|
|
26
|
-
|
|
27
|
-
zip.put_next_entry "word/settings.xml"
|
|
28
|
-
zip.write DocXify::Template.settings
|
|
29
|
-
|
|
30
|
-
zip.put_next_entry "word/styles.xml"
|
|
31
|
-
zip.write DocXify::Template.styles
|
|
32
|
-
|
|
33
|
-
zip.put_next_entry "word/webSettings.xml"
|
|
34
|
-
zip.write DocXify::Template.web_settings
|
|
35
|
-
|
|
36
|
-
zip.put_next_entry "word/document.xml"
|
|
37
|
-
zip.write document.build_xml(self)
|
|
38
|
-
|
|
39
|
-
zip.put_next_entry "word/_rels/document.xml.rels"
|
|
40
|
-
zip.write document_xml_rels
|
|
16
|
+
write_entry zip, "_rels/.rels", DocXify::Template.top_level_rels
|
|
17
|
+
write_entry zip, "[Content_Types].xml", DocXify::Template.content_types
|
|
18
|
+
write_entry zip, "word/theme/theme1.xml", DocXify::Template.theme
|
|
19
|
+
write_entry zip, "word/fontTable.xml", DocXify::Template.font_table
|
|
20
|
+
write_entry zip, "word/settings.xml", DocXify::Template.settings
|
|
21
|
+
write_entry zip, "word/styles.xml", DocXify::Template.styles
|
|
22
|
+
write_entry zip, "word/webSettings.xml", DocXify::Template.web_settings
|
|
23
|
+
write_entry zip, "word/document.xml", document.build_xml(self)
|
|
24
|
+
write_entry zip, "word/_rels/document.xml.rels", document_xml_rels
|
|
41
25
|
|
|
42
26
|
@document.relationships.each do |relation|
|
|
43
27
|
if relation.is_a?(DocXify::Element::File)
|
|
44
|
-
zip
|
|
45
|
-
zip.write relation.data
|
|
28
|
+
write_entry zip, "word/media/#{relation.filename}", relation.data
|
|
46
29
|
end
|
|
47
30
|
end
|
|
48
31
|
end
|
|
@@ -73,5 +56,16 @@ module DocXify
|
|
|
73
56
|
xml << "</Relationships>"
|
|
74
57
|
xml
|
|
75
58
|
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
# Word and other OPC readers reject Zip64 headers. Since rubyzip 3 defaults
|
|
63
|
+
# to Zip64 for any entry whose size is unknown while its local header is
|
|
64
|
+
# streamed out, declare the size up front (all entry data is already in
|
|
65
|
+
# memory) so entries stay in the classic zip format.
|
|
66
|
+
def write_entry(zip, name, data)
|
|
67
|
+
zip.put_next_entry Zip::Entry.new(nil, name, size: data.bytesize)
|
|
68
|
+
zip.write data
|
|
69
|
+
end
|
|
76
70
|
end
|
|
77
71
|
end
|
data/lib/docxify/document.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module DocXify
|
|
2
2
|
class Document
|
|
3
3
|
attr_accessor :font, :size, :color, :background, :margins, :page_layout
|
|
4
|
-
attr_reader :content, :relationships, :width
|
|
4
|
+
attr_reader :content, :relationships, :width, :height
|
|
5
5
|
|
|
6
6
|
def initialize(options = {})
|
|
7
7
|
@content = []
|
|
@@ -51,7 +51,7 @@ module DocXify
|
|
|
51
51
|
XML
|
|
52
52
|
|
|
53
53
|
# See the note in DocXify::Element::PageLayout for why it's not just handled the same as any other element
|
|
54
|
-
@page_layout = DocXify::Element::PageLayout.new(width: @width, height: @height, orientation: @
|
|
54
|
+
@page_layout = DocXify::Element::PageLayout.new(width: @width, height: @height, orientation: @orientation, document: self)
|
|
55
55
|
|
|
56
56
|
@content.each do |element|
|
|
57
57
|
if element.is_a?(DocXify::Element::PageLayout)
|
|
@@ -27,7 +27,7 @@ module DocXify
|
|
|
27
27
|
def to_s(_container = nil)
|
|
28
28
|
<<~XML
|
|
29
29
|
<w:sectPr>
|
|
30
|
-
<w:pgSz w:w="#{@width}" w:h="#{@height}" #{'w:orient="portrait
|
|
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
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
32
|
<w:cols w:space="708"/>
|
|
33
33
|
<w:docGrid w:linePitch="360"/>
|
data/lib/docxify/version.rb
CHANGED
data/lib/docxify.rb
CHANGED
|
@@ -19,7 +19,7 @@ module DocXify
|
|
|
19
19
|
|
|
20
20
|
UNITS_PER_CM = (1440 / 2.54)
|
|
21
21
|
A4_PORTRAIT_WIDTH = 11_906 # cm2dxa(21)
|
|
22
|
-
A4_PORTRAIT_HEIGHT =
|
|
22
|
+
A4_PORTRAIT_HEIGHT = 16_838 # cm2dxa(29.7)
|
|
23
23
|
A4_LANDSCAPE_WIDTH = A4_PORTRAIT_HEIGHT
|
|
24
24
|
A4_LANDSCAPE_HEIGHT = A4_PORTRAIT_WIDTH
|
|
25
25
|
|
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.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Jeffries
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '3.6'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '3.6'
|
|
41
41
|
description: Using a relatively simple DSL, you can generate Word DocX documents from
|
|
42
42
|
Ruby.
|
|
43
43
|
email:
|
|
@@ -48,6 +48,7 @@ extra_rdoc_files: []
|
|
|
48
48
|
files:
|
|
49
49
|
- ".rspec"
|
|
50
50
|
- ".rubocop.yml"
|
|
51
|
+
- ".ruby-version"
|
|
51
52
|
- CHANGELOG.md
|
|
52
53
|
- LICENSE.md
|
|
53
54
|
- README.md
|
|
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
88
89
|
- !ruby/object:Gem::Version
|
|
89
90
|
version: '0'
|
|
90
91
|
requirements: []
|
|
91
|
-
rubygems_version: 4.0.
|
|
92
|
+
rubygems_version: 4.0.10
|
|
92
93
|
specification_version: 4
|
|
93
94
|
summary: DocXify is a gem to help you generate Word documents from Ruby.
|
|
94
95
|
test_files: []
|