Class: Uniword::Builder::FootnoteBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/builder/footnote_builder.rb

Overview

Builds footnotes and endnotes for documents.

Manages footnote/endnote creation, ID assignment, and wiring references into the document body.

Examples:

Add footnotes to a document

doc = DocumentBuilder.new
doc.paragraph { |p| p << 'See the '; p << doc.footnote('A note') }

Add endnotes

doc.paragraph { |p| p << 'See '; p << doc.endnote('An endnote') }

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ FootnoteBuilder

Returns a new instance of FootnoteBuilder.



17
18
19
# File 'lib/uniword/builder/footnote_builder.rb', line 17

def initialize(document)
  @document = document
end

Instance Method Details

#endnote(text = nil) {|ParagraphBuilder| ... } ⇒ Wordprocessingml::Run

Create an endnote and return a Run with an endnoteReference.

Parameters:

  • text (String) (defaults to: nil)

    Endnote text content

Yields:

Returns:



44
45
46
47
48
49
50
51
# File 'lib/uniword/builder/footnote_builder.rb', line 44

def endnote(text = nil, &)
  id = next_endnote_id
  run = Wordprocessingml::Run.new(
    endnote_reference: Wordprocessingml::EndnoteReference.new(id: id.to_s)
  )
  create_endnote_entry(id, text, &)
  run
end

#footnote(text = nil) {|ParagraphBuilder| ... } ⇒ Wordprocessingml::Run

Create a footnote and return a Run with a footnoteReference.

The footnote body is stored in the document’s footnotes collection. The returned Run contains a <w:footnoteReference> element that Word uses to link to the footnote body.

Parameters:

  • text (String) (defaults to: nil)

    Footnote text content

Yields:

Returns:



30
31
32
33
34
35
36
37
# File 'lib/uniword/builder/footnote_builder.rb', line 30

def footnote(text = nil, &)
  id = next_footnote_id
  run = Wordprocessingml::Run.new(
    footnote_reference: Wordprocessingml::FootnoteReference.new(id: id.to_s)
  )
  create_footnote_entry(id, text, &)
  run
end