Class: Uniword::Docx::PartLoader::RawPartLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/docx/part_loader/raw_part_loader.rb

Overview

Fallback loader: preserves ZIP entries no registry definition claims as raw parts (RawPart) on the package, so unmodelled parts (docProps/meta.xml, glossary documents, VBA projects, unmodelled .rels sidecars, ...) round-trip byte-for-byte with their content types and relationships intact.

Runs last (load_priority 130 on the :raw_parts definition), so the registry claims every path it models first and this loader carries only the remainder — no double emission. A path is claimed when any PartDefinition matches it (loadable or not), when it is the resolved main document part (or its rels sidecar) at a non-standard location, or when it is a customXml item rels sidecar consumed by CustomXmlLoader.

Non-compliant parts (no content type declaration, OS artifact, ...) are stripped at load when Uniword.configuration.on_noncompliant_content is :strip (the default, matching Word's behavior). In :raise mode the parts are preserved and the save-time integrity gate raises with structured OPC-005 issues.

Bytes are re-read from the original ZIP when available (the extracted hash may carry corrupted UTF-8 binary); content types come from the loaded [Content_Types].xml model.

Constant Summary collapse

CUSTOM_XML_ITEM_RELS =

customXml item rels sidecars are consumed by CustomXmlLoader together with their item part (captured group: item index).

%r{\AcustomXml/_rels/item(\d+)\.xml\.rels\z}

Instance Method Summary collapse

Instance Method Details

#load(context, _definition) ⇒ void

This method returns an undefined value.

Parameters:

  • context (LoadContext)

    shared load state

  • _definition (Ooxml::PartDefinition)

    :raw_parts (strategy interface; the loader claims by remainder, not by definition matching)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/uniword/docx/part_loader/raw_part_loader.rb', line 41

def load(context, _definition)
  preservable, stripped = partition_unclaimed(context)

  record_stripped(context, stripped)
  return if preservable.empty?

  bytes = raw_bytes(context, preservable)
  rels_by_target = relationships_by_target(context.package)

  preservable.each do |path|
    next unless bytes[path]

    context.package.raw_parts[path] = build_part(
      context.package, path, bytes[path], rels_by_target
    )
  end
end