Class: Uniword::Builder::ParagraphBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- Uniword::Builder::ParagraphBuilder
- Includes:
- HasBorders, HasShading
- Defined in:
- lib/uniword/builder/paragraph_builder.rb
Overview
Builds and configures Paragraph objects.
Uses << operator to append child elements with smart type routing.
Instance Attribute Summary
Attributes inherited from BaseBuilder
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(element) ⇒ self
Append a child element.
- #align=(value) ⇒ Object
- #contextual_spacing=(value) ⇒ Object
-
#indent(left: nil, right: nil, first_line: nil, hanging: nil) ⇒ self
Set paragraph indentation.
- #keep_next(value = true) ⇒ Object
-
#numbering(num_id, level = 0) ⇒ self
Set numbering.
- #outline_level=(value) ⇒ Object
- #page_break_before(value = true) ⇒ Object
-
#spacing(before: nil, after: nil, line: nil, rule: nil) ⇒ self
Set paragraph spacing.
- #style=(name) ⇒ Object
Methods included from HasShading
Methods included from HasBorders
Methods inherited from BaseBuilder
#build, from_model, #initialize
Constructor Details
This class inherits a constructor from Uniword::Builder::BaseBuilder
Class Method Details
.default_model_class ⇒ Object
25 26 27 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 25 def self.default_model_class Wordprocessingml::Paragraph end |
Instance Method Details
#<<(element) ⇒ self
Append a child element. Routes by type:
-
String -> creates a Run
-
Run -> appends to runs
-
Hyperlink -> appends to hyperlinks
-
TabStop -> appends to properties.tabs
-
BookmarkStart/End -> appends to bookmarks
-
StructuredDocumentTag -> appends to sdts
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 39 def <<(element) case element when String @model.runs << Wordprocessingml::Run.new(text: element) when Wordprocessingml::Run @model.runs << element when Wordprocessingml::Hyperlink @model.hyperlinks << element when Properties::TabStop ensure_properties @model.properties.tabs ||= Properties::Tabs.new @model.properties.tabs << element when Wordprocessingml::BookmarkStart @model.bookmark_starts << element when Wordprocessingml::BookmarkEnd @model.bookmark_ends << element when Wordprocessingml::StructuredDocumentTag @model.sdts << element when RunBuilder @model.runs << element.build else raise ArgumentError, "Cannot add #{element.class} to paragraph" end self end |
#align=(value) ⇒ Object
70 71 72 73 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 70 def align=(value) ensure_properties.alignment = Properties::Alignment.new(value: value.to_s) self end |
#contextual_spacing=(value) ⇒ Object
137 138 139 140 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 137 def contextual_spacing=(value) ensure_properties.contextual_spacing = value self end |
#indent(left: nil, right: nil, first_line: nil, hanging: nil) ⇒ self
Set paragraph indentation
99 100 101 102 103 104 105 106 107 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 99 def indent(left: nil, right: nil, first_line: nil, hanging: nil) ensure_properties.indentation ||= Properties::Indentation.new ind = @model.properties.indentation ind.left = left if left ind.right = right if right ind.first_line = first_line if first_line ind.hanging = hanging if hanging self end |
#keep_next(value = true) ⇒ Object
125 126 127 128 129 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 125 def keep_next(value = true) ensure_properties.keep_next_wrapper = value ? Properties::KeepNext.new(value: true) : nil self end |
#numbering(num_id, level = 0) ⇒ self
Set numbering
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 114 def numbering(num_id, level = 0) props = ensure_properties props.num_id = num_id props.ilvl = level props.numbering_properties = Properties::NumberingProperties.new( num_id: Properties::NumberingId.new(value: num_id), ilvl: Properties::NumberingLevel.new(value: level), ) self end |
#outline_level=(value) ⇒ Object
142 143 144 145 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 142 def outline_level=(value) ensure_properties.outline_level = value self end |
#page_break_before(value = true) ⇒ Object
131 132 133 134 135 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 131 def page_break_before(value = true) ensure_properties.page_break_before_wrapper = value ? Properties::PageBreakBefore.new(value: true) : nil self end |
#spacing(before: nil, after: nil, line: nil, rule: nil) ⇒ self
Set paragraph spacing
82 83 84 85 86 87 88 89 90 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 82 def spacing(before: nil, after: nil, line: nil, rule: nil) ensure_properties.spacing ||= Properties::Spacing.new props = @model.properties.spacing props.before = before if before props.after = after if after props.line = line if line props.line_rule = rule if rule self end |
#style=(name) ⇒ Object
65 66 67 68 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 65 def style=(name) ensure_properties.style = Properties::StyleReference.new(value: name) self end |