Class: Uniword::Mhtml::MhtmlPackage

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/uniword/mhtml/mhtml_package.rb

Overview

MHTML Package — MIME-based Word format (.mht, .mhtml, .doc).

IMPORTANT: This is COMPLETELY SEPARATE from OOXML Docx::Package.

  • OOXML uses ZIP + XML parts

  • MHTML uses MIME + HTML content

  • They share NO classes!

Examples:

Load MHTML file

document = MhtmlPackage.from_file('document.mhtml')

Save MHTML file

MhtmlPackage.to_file(document, 'output.doc')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filelist_xmlObject

Returns the value of attribute filelist_xml.



28
29
30
# File 'lib/uniword/mhtml/mhtml_package.rb', line 28

def filelist_xml
  @filelist_xml
end

#imagesObject

Returns the value of attribute images.



28
29
30
# File 'lib/uniword/mhtml/mhtml_package.rb', line 28

def images
  @images
end

#raw_html_contentObject

Legacy accessors for backward compatibility



27
28
29
# File 'lib/uniword/mhtml/mhtml_package.rb', line 27

def raw_html_content
  @raw_html_content
end

Class Method Details

.from_file(path) ⇒ Document

Load MHTML file and return a populated Document model.

Parameters:

  • path (String)

    Path to .mht, .mhtml, or .doc file

Returns:

  • (Document)

    Loaded document with all MIME parts



34
35
36
37
# File 'lib/uniword/mhtml/mhtml_package.rb', line 34

def self.from_file(path)
  parser = Infrastructure::MimeParser.new
  parser.parse(path)
end

.supported_extensionsObject



51
52
53
# File 'lib/uniword/mhtml/mhtml_package.rb', line 51

def self.supported_extensions
  [".mht", ".mhtml", ".doc"]
end

.to_file(document, path) ⇒ Object

Save MHTML Document to file.

Parameters:



43
44
45
46
47
48
49
# File 'lib/uniword/mhtml/mhtml_package.rb', line 43

def self.to_file(document, path)
  # Convert OOXML DocumentRoot to Mhtml::Document if needed
  document = Transformation::Transformer.new.docx_to_mhtml(document) if document.is_a?(Uniword::Wordprocessingml::DocumentRoot)

  packager = Infrastructure::MimePackager.from_document(document)
  packager.package(path)
end

Instance Method Details

#to_mime_partsObject

Legacy compatibility: convert to MIME parts hash



56
57
58
59
60
61
62
# File 'lib/uniword/mhtml/mhtml_package.rb', line 56

def to_mime_parts
  {
    "html" => raw_html_content,
    "filelist" => filelist_xml,
    "images" => images || {},
  }
end