Class: Uniword::Wordprocessingml::ParagraphProperties
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Wordprocessingml::ParagraphProperties
- Defined in:
- lib/uniword/wordprocessingml/paragraph_properties.rb
Overview
Paragraph formatting properties
Represents w:pPr element containing paragraph-level formatting. Used in StyleSets and document paragraph elements.
Instance Method Summary collapse
-
#convert_flat_attributes! ⇒ Object
Convert flat convenience attributes to proper wrapper objects This handles cases like ParagraphProperties.new(spacing_before: 120) where the flat attribute is set but the wrapper object is not.
-
#initialize(attrs = {}) ⇒ ParagraphProperties
constructor
Initialize with defaults and handle convenience attributes.
- #yaml_alignment_from(instance, value) ⇒ Object
- #yaml_alignment_to(instance, _doc) ⇒ Object
- #yaml_contextual_spacing_from(instance, value) ⇒ Object
- #yaml_contextual_spacing_to(instance, _doc) ⇒ Object
- #yaml_keep_lines_from(instance, value) ⇒ Object
- #yaml_keep_lines_to(instance, _doc) ⇒ Object
- #yaml_keep_next_from(instance, value) ⇒ Object
- #yaml_keep_next_to(instance, _doc) ⇒ Object
- #yaml_outline_level_from(instance, value) ⇒ Object
- #yaml_outline_level_to(instance, _doc) ⇒ Object
- #yaml_page_break_before_from(instance, value) ⇒ Object
- #yaml_page_break_before_to(instance, _doc) ⇒ Object
-
#yaml_style_from(instance, value) ⇒ Object
YAML transform methods (instance methods - called via send on an instance).
- #yaml_style_to(instance, _doc) ⇒ Object
- #yaml_widow_control_from(instance, value) ⇒ Object
- #yaml_widow_control_to(instance, _doc) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ ParagraphProperties
Initialize with defaults and handle convenience attributes
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 256 def initialize(attrs = {}) # Save wrapper attribute values before super clears them keep_next_val = attrs.key?(:keep_next) ? attrs.delete(:keep_next) : nil keep_lines_val = attrs.key?(:keep_lines) ? attrs.delete(:keep_lines) : nil page_break_before_val = attrs.key?(:page_break_before) ? attrs.delete(:page_break_before) : nil widow_control_val = attrs.key?(:widow_control) ? attrs.delete(:widow_control) : nil style_val = attrs.key?(:style) ? attrs.delete(:style) : nil super # Set wrapper attributes after super (super clears them) if keep_next_val self.keep_next_wrapper = Properties::KeepNext.new(value: keep_next_val) end if keep_lines_val self.keep_lines_wrapper = Properties::KeepLines.new(value: keep_lines_val) end if page_break_before_val self.page_break_before_wrapper = Properties::PageBreakBefore.new(value: page_break_before_val) end unless widow_control_val.nil? self.widow_control_wrapper = Properties::WidowControl.new(value: widow_control_val) end self.style = style_val if style_val # Convert flat attributes to wrapper objects (Pattern 0: after super) convert_flat_attributes! end |
Instance Method Details
#convert_flat_attributes! ⇒ Object
Convert flat convenience attributes to proper wrapper objects This handles cases like ParagraphProperties.new(spacing_before: 120) where the flat attribute is set but the wrapper object is not
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 290 def convert_flat_attributes! # Style - convert string to StyleReference wrapper self.style = Properties::StyleReference.new(value: @style) if @style.is_a?(String) # Alignment - convert string to Alignment wrapper self.alignment = Properties::Alignment.new(value: @alignment) if @alignment.is_a?(String) # Spacing - create spacing object from flat spacing attributes if (@spacing_before || @spacing_after || @line_spacing || @line_rule) && !@spacing self.spacing = Properties::Spacing.new spacing.before = @spacing_before if @spacing_before spacing.after = @spacing_after if @spacing_after spacing.line = @line_spacing.to_i if @line_spacing spacing.line_rule = @line_rule if @line_rule end # Indentation - create indentation object from flat indent attributes if (@indent_left || @indent_right || @indent_first_line) && !@indentation self.indentation = Properties::Indentation.new indentation.left = @indent_left if @indent_left indentation.right = @indent_right if @indent_right indentation.first_line = @indent_first_line if @indent_first_line end # Run properties from flat attributes return unless @run_properties && !@run_properties.is_a?(RunProperties) rp = RunProperties.new rp.bold = @run_properties[:bold] if @run_properties[:bold] rp.italic = @run_properties[:italic] if @run_properties[:italic] rp.underline = @run_properties[:underline] if @run_properties[:underline] rp.color = @run_properties[:color] if @run_properties[:color] rp.font = @run_properties[:font] if @run_properties[:font] rp.size = @run_properties[:size] if @run_properties[:size] @run_properties = rp end |
#yaml_alignment_from(instance, value) ⇒ Object
125 126 127 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 125 def yaml_alignment_from(instance, value) instance.alignment = Properties::Alignment.new(value: value) if value end |
#yaml_alignment_to(instance, _doc) ⇒ Object
129 130 131 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 129 def yaml_alignment_to(instance, _doc) instance.alignment&.value end |
#yaml_contextual_spacing_from(instance, value) ⇒ Object
157 158 159 160 161 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 157 def yaml_contextual_spacing_from(instance, value) return if value.nil? instance.contextual_spacing = Properties::ContextualSpacing.new(value: value) end |
#yaml_contextual_spacing_to(instance, _doc) ⇒ Object
163 164 165 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 163 def yaml_contextual_spacing_to(instance, _doc) instance.contextual_spacing&.value end |
#yaml_keep_lines_from(instance, value) ⇒ Object
141 142 143 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 141 def yaml_keep_lines_from(instance, value) instance.keep_lines_wrapper = Properties::KeepLines.new(value: value) unless value.nil? end |
#yaml_keep_lines_to(instance, _doc) ⇒ Object
145 146 147 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 145 def yaml_keep_lines_to(instance, _doc) instance.keep_lines_wrapper&.value end |
#yaml_keep_next_from(instance, value) ⇒ Object
133 134 135 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 133 def yaml_keep_next_from(instance, value) instance.keep_next_wrapper = Properties::KeepNext.new(value: value) unless value.nil? end |
#yaml_keep_next_to(instance, _doc) ⇒ Object
137 138 139 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 137 def yaml_keep_next_to(instance, _doc) instance.keep_next_wrapper&.value end |
#yaml_outline_level_from(instance, value) ⇒ Object
149 150 151 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 149 def yaml_outline_level_from(instance, value) instance.outline_level = Properties::OutlineLevel.new(value: value.to_i) if value end |
#yaml_outline_level_to(instance, _doc) ⇒ Object
153 154 155 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 153 def yaml_outline_level_to(instance, _doc) instance.outline_level&.value end |
#yaml_page_break_before_from(instance, value) ⇒ Object
167 168 169 170 171 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 167 def yaml_page_break_before_from(instance, value) return if value.nil? instance.page_break_before_wrapper = Properties::PageBreakBefore.new(value: value) end |
#yaml_page_break_before_to(instance, _doc) ⇒ Object
173 174 175 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 173 def yaml_page_break_before_to(instance, _doc) instance.page_break_before_wrapper&.value end |
#yaml_style_from(instance, value) ⇒ Object
YAML transform methods (instance methods - called via send on an instance)
117 118 119 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 117 def yaml_style_from(instance, value) instance.style = Properties::StyleReference.new(value: value) if value end |
#yaml_style_to(instance, _doc) ⇒ Object
121 122 123 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 121 def yaml_style_to(instance, _doc) instance.style&.value end |
#yaml_widow_control_from(instance, value) ⇒ Object
177 178 179 180 181 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 177 def yaml_widow_control_from(instance, value) return if value.nil? instance.widow_control_wrapper = Properties::WidowControl.new(value: value) end |
#yaml_widow_control_to(instance, _doc) ⇒ Object
183 184 185 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 183 def yaml_widow_control_to(instance, _doc) instance.widow_control_wrapper&.value end |