Class: Uniword::Builder::SectionBuilder

Inherits:
BaseBuilder show all
Defined in:
lib/uniword/builder/section_builder.rb

Overview

Builds and configures SectionProperties objects.

Examples:

Configure page setup

doc.section do |s|
  s.page_size(width: 12240, height: 15840)
  s.margins(top: 1440, bottom: 1440, left: 1440, right: 1440)
end

Configure section with page numbering

doc.section(type: 'nextPage') do |s|
  s.page_size(orientation: 'landscape')
  s.page_numbering(start: 1, format: 'lowerRoman')
  s.margins(top: 720, bottom: 720)
end

Instance Attribute Summary

Attributes inherited from BaseBuilder

#model

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseBuilder

#build, from_model

Constructor Details

#initialize(model = nil) ⇒ SectionBuilder

Returns a new instance of SectionBuilder.



24
25
26
27
# File 'lib/uniword/builder/section_builder.rb', line 24

def initialize(model = nil)
  super
  ensure_section_defaults
end

Class Method Details

.default_model_classObject



20
21
22
# File 'lib/uniword/builder/section_builder.rb', line 20

def self.default_model_class
  Wordprocessingml::SectionProperties
end

Instance Method Details

#columns(count: 1, spacing: 720) ⇒ Object



64
65
66
67
68
69
# File 'lib/uniword/builder/section_builder.rb', line 64

def columns(count: 1, spacing: 720)
  @model.columns ||= Wordprocessingml::Columns.new
  @model.columns.num = count
  @model.columns.space = spacing
  self
end


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/uniword/builder/section_builder.rb', line 83

def footer(type: "default", &block)
  hf = HeaderFooterBuilder.new(:footer, type: type)
  block&.call(hf)
  ref = Wordprocessingml::FooterReference.new(
    type: type, r_id: "rIdFtr#{type}",
  )
  @model.footer_references << ref
  @footer_builders ||= {}
  @footer_builders[type] = hf
  hf
end

Built footer content models keyed by type.



101
102
103
# File 'lib/uniword/builder/section_builder.rb', line 101

def footer_models
  (@footer_builders || {}).transform_values(&:build)
end

#header(type: "default", &block) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/uniword/builder/section_builder.rb', line 71

def header(type: "default", &block)
  hf = HeaderFooterBuilder.new(:header, type: type)
  block&.call(hf)
  ref = Wordprocessingml::HeaderReference.new(
    type: type, r_id: "rIdHdr#{type}",
  )
  @model.header_references << ref
  @header_builders ||= {}
  @header_builders[type] = hf
  hf
end

#header_modelsObject

Built header content models keyed by type.



96
97
98
# File 'lib/uniword/builder/section_builder.rb', line 96

def header_models
  (@header_builders || {}).transform_values(&:build)
end

#margins(top: 1440, bottom: 1440, left: 1440, right: 1440, header: 720, footer: 720, gutter: 0) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/uniword/builder/section_builder.rb', line 44

def margins(top: 1440, bottom: 1440, left: 1440, right: 1440,
            header: 720, footer: 720, gutter: 0)
  @model.page_margins ||= Wordprocessingml::PageMargins.new
  @model.page_margins.top = top
  @model.page_margins.bottom = bottom
  @model.page_margins.left = left
  @model.page_margins.right = right
  @model.page_margins.header = header
  @model.page_margins.footer = footer
  @model.page_margins.gutter = gutter
  self
end

#page_numbering(start: nil, format: nil) ⇒ Object



57
58
59
60
61
62
# File 'lib/uniword/builder/section_builder.rb', line 57

def page_numbering(start: nil, format: nil)
  @model.page_numbering ||= Wordprocessingml::PageNumbering.new
  @model.page_numbering.start = start if start
  @model.page_numbering.format = format if format
  self
end

#page_size(width: Wordprocessingml::PageDefaults::LETTER_WIDTH, height: Wordprocessingml::PageDefaults::LETTER_HEIGHT, orientation: "portrait") ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/uniword/builder/section_builder.rb', line 34

def page_size(width: Wordprocessingml::PageDefaults::LETTER_WIDTH,
               height: Wordprocessingml::PageDefaults::LETTER_HEIGHT,
               orientation: "portrait")
  @model.page_size ||= Wordprocessingml::PageSize.new
  @model.page_size.width = width
  @model.page_size.height = height
  @model.page_size.orientation = orientation
  self
end

#type=(value) ⇒ Object



29
30
31
32
# File 'lib/uniword/builder/section_builder.rb', line 29

def type=(value)
  @model.type = value
  self
end