Class: Hlsv::DocxWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/hlsv/html2word.rb

Overview


DOCX Writer

Instance Method Summary collapse

Constructor Details

#initialize(output_path) ⇒ DocxWriter

Returns a new instance of DocxWriter.



559
560
561
# File 'lib/hlsv/html2word.rb', line 559

def initialize(output_path)
  @output_path = output_path
end

Instance Method Details

#write(blocks) ⇒ Object



563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'lib/hlsv/html2word.rb', line 563

def write(blocks)
  cover_block = blocks.find { |b| b.type == :cover }
  doc_title   = cover_block&.content&.dig(:title).to_s

  ::Zip::OutputStream.open(@output_path) do |zip|
    add_xml(zip, '[Content_Types].xml',          OoxmlBuilder.content_types)
    add_xml(zip, '_rels/.rels',                  OoxmlBuilder.rels)
    add_xml(zip, 'word/document.xml',            OoxmlBuilder.document(blocks))
    add_xml(zip, 'word/styles.xml',              OoxmlBuilder.styles)
    add_xml(zip, 'word/numbering.xml',           OoxmlBuilder.numbering)
    add_xml(zip, 'word/settings.xml',            OoxmlBuilder.settings)
    add_xml(zip, 'word/_rels/document.xml.rels', OoxmlBuilder.word_rels)
    add_xml(zip, 'word/footer1.xml',             OoxmlBuilder.footer_xml(doc_title))
    add_xml(zip, 'word/_rels/footer1.xml.rels',  OoxmlBuilder.empty_rels)
  end
end