docxify 0.0.7 → 0.0.8
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 +6 -0
- data/README.md +20 -20
- data/lib/docxify/document.rb +19 -9
- data/lib/docxify/element/page_break.rb +0 -1
- data/lib/docxify/version.rb +1 -1
- data/lib/docxify.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ce756578c53df736bb1a6641722c8915ccc6bfdf24ce19c21e4bd64624f8405
|
4
|
+
data.tar.gz: 62039225ee265819d72a6cd6ef64a6cd7150b89d99f93fc1a0dfcf7994cafa4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514adbdd7c383dc3a373f460b9c548b532e3885b16d75030e5a12e070a13d41e3addab9cbed4cd89794e2bb057e67599e44d1399981d5a6e94c9fb1c5747dc6c
|
7
|
+
data.tar.gz: d3d04f7f8ad20fcdc4478cfe07247f4dc1d687423d4df46336ffd742cbbf941846e8831b8344279db182c324e3eac515856937152162be89f84590c095d80f14
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -41,26 +41,26 @@ gem install docxify
|
|
41
41
|
|
42
42
|
@docx.add_page_break
|
43
43
|
|
44
|
-
@docx.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
44
|
+
@docx.page_layout width: DocXify::A4_PORTRAIT_HEIGHT, height: DocXify::A4_PORTRAIT_WIDTH, orientation: :landscape
|
45
|
+
|
46
|
+
rows = []
|
47
|
+
rows << [
|
48
|
+
DocXify::Element::TableCell.new("<b>Header 1</b>"),
|
49
|
+
DocXify::Element::TableCell.new("<b>Header 2</b>")
|
50
|
+
DocXify::Element::TableCell.new("<b>Header 3</b>")
|
51
|
+
DocXify::Element::TableCell.new("<b>Header 4</b>", width_cm: 10)
|
52
|
+
]
|
53
|
+
rows << [
|
54
|
+
DocXify::Element::TableCell.new("Content 1", valign: :center, align: :left, nowrap: true, colspan: 3),
|
55
|
+
DocXify::Element::TableCell.new("Rowspan <b>here</b>", rowspan: true) # merges until a "nil" cell
|
56
|
+
]
|
57
|
+
rows << [
|
58
|
+
DocXify::Element::TableCell.new("Secondary 1")
|
59
|
+
DocXify::Element::TableCell.new("Secondary 2")
|
60
|
+
DocXify::Element::TableCell.new("Secondary 3")
|
61
|
+
DocXify::Element::TableCell.new(nil) # Word requires that there's an empty cell merged with the previous rowspan
|
62
|
+
]
|
63
|
+
container.add_table rows
|
64
64
|
|
65
65
|
docx_binary_data = @docx.render
|
66
66
|
# or
|
data/lib/docxify/document.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module DocXify
|
2
2
|
class Document
|
3
|
-
attr_accessor :font, :size, :color, :background
|
3
|
+
attr_accessor :font, :size, :color, :background, :margins, :page_layout
|
4
4
|
attr_reader :content, :relationships, :width
|
5
5
|
|
6
6
|
def initialize(options = {})
|
@@ -8,11 +8,12 @@ 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
12
|
@font = options[:font] || "Times New Roman"
|
12
13
|
@size = options[:size] || 12
|
13
14
|
@color = options[:color] || 12
|
14
15
|
@background = options[:background] if options[:background]
|
15
|
-
@margins = { top: 2, bottom: 2, left: 2, right: 2 }
|
16
|
+
@margins = { top: 2, bottom: 2, left: 2, right: 2 }.merge(options[:margins] || {})
|
16
17
|
end
|
17
18
|
|
18
19
|
def default_styling(options = {})
|
@@ -41,17 +42,21 @@ module DocXify
|
|
41
42
|
<w:body>
|
42
43
|
XML
|
43
44
|
|
45
|
+
# See the note in DocXify::Element::PageLayout for why it's not just handled the same as any other element
|
46
|
+
@page_layout = DocXify::Element::PageLayout.new(width: @width, height: @height, orientation: @orientatation, document: self)
|
47
|
+
|
44
48
|
@content.each do |element|
|
45
|
-
|
49
|
+
if element.is_a?(DocXify::Element::PageLayout)
|
50
|
+
xml << @page_layout.to_s
|
51
|
+
@page_layout = element
|
52
|
+
else
|
53
|
+
xml << element.to_s(container)
|
54
|
+
end
|
46
55
|
end
|
47
56
|
|
57
|
+
xml << @page_layout.to_s
|
58
|
+
|
48
59
|
xml << <<~XML
|
49
|
-
<w:sectPr >
|
50
|
-
<w:pgSz w:h="#{@height}" w:w="#{@width}"/>
|
51
|
-
<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]}"/>
|
52
|
-
<w:cols w:space="708"/>
|
53
|
-
<w:docGrid w:linePitch="360"/>
|
54
|
-
</w:sectPr>
|
55
60
|
</w:body>
|
56
61
|
</w:document>
|
57
62
|
XML
|
@@ -82,6 +87,11 @@ module DocXify
|
|
82
87
|
add DocXify::Element::PageBreak.new
|
83
88
|
end
|
84
89
|
|
90
|
+
def add_page_layout(options = {})
|
91
|
+
options[:document] = self
|
92
|
+
add DocXify::Element::PageLayout.new(options)
|
93
|
+
end
|
94
|
+
|
85
95
|
def add_divider
|
86
96
|
add DocXify::Element::Divider.new
|
87
97
|
end
|
data/lib/docxify/version.rb
CHANGED
data/lib/docxify.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative "docxify/element/divider"
|
|
8
8
|
require_relative "docxify/element/file"
|
9
9
|
require_relative "docxify/element/image"
|
10
10
|
require_relative "docxify/element/page_break"
|
11
|
+
require_relative "docxify/element/page_layout"
|
11
12
|
require_relative "docxify/element/paragraph"
|
12
13
|
require_relative "docxify/element/table"
|
13
14
|
require_relative "docxify/element/table_cell"
|