Class: Uniword::Docx::HeaderFooterPart
- Defined in:
- lib/uniword/docx/header_footer_part.rb
Overview
A header or footer part (word/headerN.xml / word/footerN.xml) held by the package — the single storage form for both round-tripped and builder-created headers/footers.
Parts loaded from an existing DOCX carry their original r_id,
target and rel_type verbatim and are flagged loaded so the
reconciler leaves their relationships and section references
untouched. Parts added programmatically (via the Builder or the
+headers+/+footers+ views) are flagged fresh: the reconciler
assigns them a relationship and wires the sectPr reference.
The type ("default"/"first"/"even") is the sectPr reference
type — derived from the section properties on load, set by the
caller on insert. Content is usually a
Wordprocessingml::Header or Wordprocessingml::Footer model;
legacy Uniword::Header/Uniword::Footer convenience models are
stored as given and converted at serialization time so callers
can keep mutating the object they inserted.
Constant Summary collapse
- TYPES =
Valid section reference types.
%w[default first even].freeze
Constants inherited from Part
Instance Attribute Summary collapse
-
#loaded ⇒ Object
writeonly
Mark whether the part originates from a loaded package.
-
#type ⇒ String?
SectPr reference type ("default"/"first"/"even").
Attributes inherited from Part
#content, #content_type, #r_id, #rel_type, #target
Instance Method Summary collapse
-
#[](key) ⇒ Object
Hash-style read compatibility (+:type+ in addition to the Part keys).
-
#definition ⇒ Ooxml::PartDefinition?
Registry definition for this part kind.
-
#empty? ⇒ Boolean
True when the content has no paragraphs/tables.
-
#footer? ⇒ Boolean
True for footer parts.
-
#header? ⇒ Boolean
True for header parts.
-
#initialize(kind: nil, type: nil, loaded: false, **rest) ⇒ HeaderFooterPart
constructor
A new instance of HeaderFooterPart.
-
#kind ⇒ Symbol?
:header or :footer.
-
#loaded? ⇒ Boolean
True when extracted from an existing package (relationships and section references are already in place).
-
#paragraphs ⇒ Array<Wordprocessingml::Paragraph>
Content paragraphs.
-
#serializable_content ⇒ Object
The content model to serialize into the part file.
-
#tables ⇒ Array<Wordprocessingml::Table>
Content tables.
Methods inherited from Part
from_hash, #package_paths, #path
Constructor Details
#initialize(kind: nil, type: nil, loaded: false, **rest) ⇒ HeaderFooterPart
Returns a new instance of HeaderFooterPart.
36 37 38 39 40 41 |
# File 'lib/uniword/docx/header_footer_part.rb', line 36 def initialize(kind: nil, type: nil, loaded: false, **rest) super(**rest) @kind = kind @type = type&.to_s @loaded = loaded end |
Instance Attribute Details
#loaded=(value) ⇒ Object (writeonly)
Mark whether the part originates from a loaded package.
65 66 67 |
# File 'lib/uniword/docx/header_footer_part.rb', line 65 def loaded=(value) @loaded = value end |
#type ⇒ String?
Returns sectPr reference type ("default"/"first"/"even").
29 30 31 |
# File 'lib/uniword/docx/header_footer_part.rb', line 29 def type @type end |
Instance Method Details
#[](key) ⇒ Object
Hash-style read compatibility (+:type+ in addition to the Part keys).
95 96 97 |
# File 'lib/uniword/docx/header_footer_part.rb', line 95 def [](key) key.to_sym == :type ? type : super end |
#definition ⇒ Ooxml::PartDefinition?
Registry definition for this part kind.
70 71 72 |
# File 'lib/uniword/docx/header_footer_part.rb', line 70 def definition @definition ||= kind && Ooxml::PartRegistry.find_by_key(kind) end |
#empty? ⇒ Boolean
Returns true when the content has no paragraphs/tables.
87 88 89 90 91 |
# File 'lib/uniword/docx/header_footer_part.rb', line 87 def empty? return true unless content paragraphs.empty? && tables.empty? end |
#footer? ⇒ Boolean
Returns true for footer parts.
54 55 56 |
# File 'lib/uniword/docx/header_footer_part.rb', line 54 def kind == :footer end |
#header? ⇒ Boolean
Returns true for header parts.
49 50 51 |
# File 'lib/uniword/docx/header_footer_part.rb', line 49 def header? kind == :header end |
#kind ⇒ Symbol?
Returns :header or :footer.
44 45 46 |
# File 'lib/uniword/docx/header_footer_part.rb', line 44 def kind @kind ||= derive_kind end |
#loaded? ⇒ Boolean
Returns true when extracted from an existing package (relationships and section references are already in place).
60 61 62 |
# File 'lib/uniword/docx/header_footer_part.rb', line 60 def loaded? !!@loaded end |
#paragraphs ⇒ Array<Wordprocessingml::Paragraph>
Returns content paragraphs.
77 78 79 |
# File 'lib/uniword/docx/header_footer_part.rb', line 77 def paragraphs content&.paragraphs end |
#serializable_content ⇒ Object
The content model to serialize into the part file. Legacy Uniword::Header/Uniword::Footer models are converted to their Wordprocessingml counterparts (paragraph and table elements are shared, mc:Ignorable carried over); other content passes through unchanged.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/uniword/docx/header_footer_part.rb', line 106 def serializable_content case content when Uniword::Header convert_legacy(Wordprocessingml::Header.new) when Uniword::Footer convert_legacy(Wordprocessingml::Footer.new) else content end end |
#tables ⇒ Array<Wordprocessingml::Table>
Returns content tables.
82 83 84 |
# File 'lib/uniword/docx/header_footer_part.rb', line 82 def tables content&.tables end |