Class: Uniword::Builder::ParagraphBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- Uniword::Builder::ParagraphBuilder
- Includes:
- HasBorders, HasShading
- Defined in:
- lib/uniword/builder/paragraph_builder.rb
Class Attribute Summary collapse
-
.mutex ⇒ Object
Returns the value of attribute mutex.
-
.sequence ⇒ Object
Returns the value of attribute sequence.
Instance Attribute Summary collapse
-
#allocator ⇒ Object
readonly
Returns the value of attribute allocator.
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.
-
#initialize(model = nil, allocator: nil) ⇒ ParagraphBuilder
constructor
A new instance of ParagraphBuilder.
- #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 ⇒ Object
- #style=(name) ⇒ Object
Methods included from HasShading
Methods included from HasBorders
Methods inherited from BaseBuilder
Constructor Details
#initialize(model = nil, allocator: nil) ⇒ ParagraphBuilder
Returns a new instance of ParagraphBuilder.
24 25 26 27 28 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 24 def initialize(model = nil, allocator: nil) @allocator = allocator super(model) assign_tracking_attributes end |
Class Attribute Details
.mutex ⇒ Object
Returns the value of attribute mutex.
15 16 17 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 15 def mutex @mutex end |
.sequence ⇒ Object
Returns the value of attribute sequence.
15 16 17 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 15 def sequence @sequence end |
Instance Attribute Details
#allocator ⇒ Object (readonly)
Returns the value of attribute allocator.
22 23 24 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 22 def allocator @allocator end |
Class Method Details
.default_model_class ⇒ Object
18 19 20 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 18 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 40 def <<(element) case element when String append_string(element) when Omml::Models::CTOMath, Omml::Models::OMath @model.o_maths << element track_element_order("oMath") when Omml::Models::OMathPara @model.o_math_paras << element track_element_order("oMathPara") when Wordprocessingml::Run append_run(element) when Wordprocessingml::Hyperlink @model.hyperlinks << element track_element_order("hyperlink") when Properties::TabStop ensure_properties @model.properties.tabs ||= Properties::Tabs.new @model.properties.tabs << element when Wordprocessingml::BookmarkStart @model.bookmark_starts << element track_element_order("bookmarkStart") when Wordprocessingml::BookmarkEnd @model.bookmark_ends << element track_element_order("bookmarkEnd") when Wordprocessingml::StructuredDocumentTag @model.sdts << element track_element_order("sdt") when Wordprocessingml::SimpleField @model.simple_fields << element track_element_order("fldSimple") when RunBuilder append_run(element.build) else raise ArgumentError, "Cannot add #{element.class} to paragraph" end self end |
#align=(value) ⇒ Object
88 89 90 91 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 88 def align=(value) ensure_properties.alignment = Properties::Alignment.new(value: value.to_s) self end |
#contextual_spacing=(value) ⇒ Object
155 156 157 158 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 155 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
117 118 119 120 121 122 123 124 125 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 117 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
143 144 145 146 147 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 143 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
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 132 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
160 161 162 163 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 160 def outline_level=(value) ensure_properties.outline_level = value self end |
#page_break_before(value = true) ⇒ Object
149 150 151 152 153 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 149 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
100 101 102 103 104 105 106 107 108 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 100 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 ⇒ Object
84 85 86 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 84 def style @model.style end |
#style=(name) ⇒ Object
79 80 81 82 |
# File 'lib/uniword/builder/paragraph_builder.rb', line 79 def style=(name) ensure_properties.style = name self end |