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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb6c9076520d0776ed132e2abbc42166a6ff0106fce181d5d178ecf3abff1a96
4
- data.tar.gz: 042d1e27e5572cd0b4868eb9af065d1b3831e25d80569eafd2086bda130ab7b1
3
+ metadata.gz: 9ce756578c53df736bb1a6641722c8915ccc6bfdf24ce19c21e4bd64624f8405
4
+ data.tar.gz: 62039225ee265819d72a6cd6ef64a6cd7150b89d99f93fc1a0dfcf7994cafa4c
5
5
  SHA512:
6
- metadata.gz: 83ee99a55280b56efd7f571c00c8cb09eb026345b821173c389f40f3bffb907bc2f4b57ce08d6d587a0bc653cdbc4efc630a1400dd48e3dee78f005bf574469e
7
- data.tar.gz: 62a9965149dde87c65db3877642fff5e6cf0cc8f02f373ab59422b78ca9a645522c2df45125268140f8b1e36b29a105b500ea06489f0fc5fee6056bff740bd6a
6
+ metadata.gz: 514adbdd7c383dc3a373f460b9c548b532e3885b16d75030e5a12e070a13d41e3addab9cbed4cd89794e2bb057e67599e44d1399981d5a6e94c9fb1c5747dc6c
7
+ data.tar.gz: d3d04f7f8ad20fcdc4478cfe07247f4dc1d687423d4df46336ffd742cbbf941846e8831b8344279db182c324e3eac515856937152162be89f84590c095d80f14
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.8
4
+
5
+ Features:
6
+
7
+ - Allow changing of following section's page layotu
8
+
3
9
  ## 0.0.7
4
10
 
5
11
  Features:
data/README.md CHANGED
@@ -41,26 +41,26 @@ gem install docxify
41
41
 
42
42
  @docx.add_page_break
43
43
 
44
- @docx.container page_width: DocXify::A4_PORTRAIT_HEIGHT, page_height: DocXify::A4_PORTRAIT_WIDTH do |container|
45
- rows = []
46
- rows << [
47
- DocXify::Element::TableCell.new("<b>Header 1</b>"),
48
- DocXify::Element::TableCell.new("<b>Header 2</b>")
49
- DocXify::Element::TableCell.new("<b>Header 3</b>")
50
- DocXify::Element::TableCell.new("<b>Header 4</b>", width_cm: 10)
51
- ]
52
- rows << [
53
- DocXify::Element::TableCell.new("Content 1", valign: :center, align: :left, nowrap: true, colspan: 3),
54
- DocXify::Element::TableCell.new("Rowspan <b>here</b>", rowspan: true) # merges until a "nil" cell
55
- ]
56
- rows << [
57
- DocXify::Element::TableCell.new("Secondary 1")
58
- DocXify::Element::TableCell.new("Secondary 2")
59
- DocXify::Element::TableCell.new("Secondary 3")
60
- DocXify::Element::TableCell.new(nil) # Word requires that there's an empty cell merged with the previous rowspan
61
- ]
62
- container.add_table rows
63
- end
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
@@ -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
- xml << element.to_s(container)
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
@@ -8,7 +8,6 @@ module DocXify
8
8
  <w:br w:type="page"/>
9
9
  </w:r>
10
10
  </w:p>
11
- <w:p/>
12
11
  XML
13
12
  end
14
13
  end
@@ -1,3 +1,3 @@
1
1
  module DocXify
2
- VERSION = "0.0.7".freeze
2
+ VERSION = "0.0.8".freeze
3
3
  end
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"
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.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries