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
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 263 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
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 326 327 328 329 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 297 def convert_flat_attributes! # 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
132 133 134 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 132 def yaml_alignment_from(instance, value) instance.alignment = Properties::Alignment.new(value: value) if value end |
#yaml_alignment_to(instance, _doc) ⇒ Object
136 137 138 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 136 def yaml_alignment_to(instance, _doc) instance.alignment&.value end |
#yaml_contextual_spacing_from(instance, value) ⇒ Object
164 165 166 167 168 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 164 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
170 171 172 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 170 def yaml_contextual_spacing_to(instance, _doc) instance.contextual_spacing&.value end |
#yaml_keep_lines_from(instance, value) ⇒ Object
148 149 150 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 148 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
152 153 154 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 152 def yaml_keep_lines_to(instance, _doc) instance.keep_lines_wrapper&.value end |
#yaml_keep_next_from(instance, value) ⇒ Object
140 141 142 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 140 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
144 145 146 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 144 def yaml_keep_next_to(instance, _doc) instance.keep_next_wrapper&.value end |
#yaml_outline_level_from(instance, value) ⇒ Object
156 157 158 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 156 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
160 161 162 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 160 def yaml_outline_level_to(instance, _doc) instance.outline_level&.value end |
#yaml_page_break_before_from(instance, value) ⇒ Object
174 175 176 177 178 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 174 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
180 181 182 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 180 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)
120 121 122 123 124 125 126 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 120 def yaml_style_from(instance, value) if value instance.style = [ Properties::StyleReference.new(value: value), ] end end |
#yaml_style_to(instance, _doc) ⇒ Object
128 129 130 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 128 def yaml_style_to(instance, _doc) Array(instance.style).first&.value end |
#yaml_widow_control_from(instance, value) ⇒ Object
184 185 186 187 188 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 184 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
190 191 192 |
# File 'lib/uniword/wordprocessingml/paragraph_properties.rb', line 190 def yaml_widow_control_to(instance, _doc) instance.widow_control_wrapper&.value end |