Class: Uniword::Section
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Section
- Defined in:
- lib/uniword/section.rb
Overview
Represents a document section Each section can have its own page setup, headers, and footers
Instance Method Summary collapse
-
#add_footer(footer) ⇒ Object
Add a footer to this section.
-
#add_header(header) ⇒ Object
Add a header to this section.
-
#default_footer ⇒ Object
Convenience accessors for different footer types.
- #default_footer=(footer) ⇒ Object
-
#default_header ⇒ Object
Convenience accessors for different header types.
- #default_header=(header) ⇒ Object
- #even_footer ⇒ Object
- #even_footer=(footer) ⇒ Object
- #even_header ⇒ Object
- #even_header=(header) ⇒ Object
- #first_footer ⇒ Object
- #first_footer=(footer) ⇒ Object
- #first_header ⇒ Object
- #first_header=(header) ⇒ Object
-
#footer(type = "default") ⇒ Object
Get or create footer by type.
-
#get_footer(type = "default") ⇒ Object
Get footer by type.
-
#get_header(type = "default") ⇒ Object
Get header by type.
-
#has_footers? ⇒ Boolean
Check if section has any footers.
-
#has_headers? ⇒ Boolean
Check if section has any headers.
-
#header(type = "default") ⇒ Object
Get or create header by type.
-
#initialize(**attributes) ⇒ Section
constructor
A new instance of Section.
-
#page_margins ⇒ Hash
Get page margins as hash (docx-js compatibility) Returns hash with margin values in twips.
-
#page_margins=(value) ⇒ Hash
Set page margins from hash (docx-js compatibility) Accepts hash with margin values in twips.
Constructor Details
#initialize(**attributes) ⇒ Section
Returns a new instance of Section.
13 14 15 16 17 18 |
# File 'lib/uniword/section.rb', line 13 def initialize(**attributes) super @properties ||= SectionProperties.a4_portrait @headers ||= [] @footers ||= [] end |
Instance Method Details
#add_footer(footer) ⇒ Object
Add a footer to this section
31 32 33 |
# File 'lib/uniword/section.rb', line 31 def () << end |
#add_header(header) ⇒ Object
Add a header to this section
21 22 23 24 25 26 27 28 |
# File 'lib/uniword/section.rb', line 21 def add_header(header) unless header.is_a?(Header) raise ArgumentError, "header must be a Header instance" end headers << header end |
#default_footer ⇒ Object
Convenience accessors for different footer types
96 97 98 |
# File 'lib/uniword/section.rb', line 96 def ("default") end |
#default_footer=(footer) ⇒ Object
100 101 102 103 104 |
# File 'lib/uniword/section.rb', line 100 def () .reject! { |f| f.type == "default" } .type = "default" if () if end |
#default_header ⇒ Object
Convenience accessors for different header types
64 65 66 |
# File 'lib/uniword/section.rb', line 64 def default_header get_header("default") end |
#default_header=(header) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/uniword/section.rb', line 68 def default_header=(header) # Remove existing default header headers.reject! { |h| h.type == "default" } header.type = "default" if header add_header(header) if header end |
#even_footer ⇒ Object
116 117 118 |
# File 'lib/uniword/section.rb', line 116 def ("even") end |
#even_footer=(footer) ⇒ Object
120 121 122 123 124 |
# File 'lib/uniword/section.rb', line 120 def () .reject! { |f| f.type == "even" } .type = "even" if () if end |
#even_header ⇒ Object
85 86 87 |
# File 'lib/uniword/section.rb', line 85 def even_header get_header("even") end |
#even_header=(header) ⇒ Object
89 90 91 92 93 |
# File 'lib/uniword/section.rb', line 89 def even_header=(header) headers.reject! { |h| h.type == "even" } header.type = "even" if header add_header(header) if header end |
#first_footer ⇒ Object
106 107 108 |
# File 'lib/uniword/section.rb', line 106 def ("first") end |
#first_footer=(footer) ⇒ Object
110 111 112 113 114 |
# File 'lib/uniword/section.rb', line 110 def () .reject! { |f| f.type == "first" } .type = "first" if () if end |
#first_header ⇒ Object
75 76 77 |
# File 'lib/uniword/section.rb', line 75 def first_header get_header("first") end |
#first_header=(header) ⇒ Object
79 80 81 82 83 |
# File 'lib/uniword/section.rb', line 79 def first_header=(header) headers.reject! { |h| h.type == "first" } header.type = "first" if header add_header(header) if header end |
#footer(type = "default") ⇒ Object
Get or create footer by type
55 56 57 58 59 60 61 |
# File 'lib/uniword/section.rb', line 55 def (type = "default") (type) || begin f = Footer.new(type: type) (f) f end end |
#get_footer(type = "default") ⇒ Object
Get footer by type
41 42 43 |
# File 'lib/uniword/section.rb', line 41 def (type = "default") .find { |f| f.type == type } end |
#get_header(type = "default") ⇒ Object
Get header by type
36 37 38 |
# File 'lib/uniword/section.rb', line 36 def get_header(type = "default") headers.find { |h| h.type == type } end |
#has_footers? ⇒ Boolean
Check if section has any footers
132 133 134 |
# File 'lib/uniword/section.rb', line 132 def .any? end |
#has_headers? ⇒ Boolean
Check if section has any headers
127 128 129 |
# File 'lib/uniword/section.rb', line 127 def has_headers? headers.any? end |
#header(type = "default") ⇒ Object
Get or create header by type
46 47 48 49 50 51 52 |
# File 'lib/uniword/section.rb', line 46 def header(type = "default") get_header(type) || begin h = Header.new(type: type) add_header(h) h end end |
#page_margins ⇒ Hash
Get page margins as hash (docx-js compatibility) Returns hash with margin values in twips
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/uniword/section.rb', line 140 def page_margins ensure_properties { top: @properties.margin_top, bottom: @properties.margin_bottom, left: @properties.margin_left, right: @properties.margin_right, header: @properties.margin_header, footer: @properties., } end |
#page_margins=(value) ⇒ Hash
Set page margins from hash (docx-js compatibility) Accepts hash with margin values in twips
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/uniword/section.rb', line 163 def page_margins=(value) return unless value.is_a?(Hash) ensure_properties @properties.margin_top = value[:top] if value.key?(:top) @properties.margin_bottom = value[:bottom] if value.key?(:bottom) @properties.margin_left = value[:left] if value.key?(:left) @properties.margin_right = value[:right] if value.key?(:right) @properties.margin_header = value[:header] if value.key?(:header) @properties. = value[:footer] if value.key?(:footer) value end |