Class: Uniword::Docx::PartLoader::ImageLoader

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

Overview

Loads image parts (word/media/*) into the document's image_parts collection, keyed by the relationship id the loaded document rels assign to each media target so downstream consumers (MHTML rendering, image manager) resolve r:embed references correctly. Media with no document-level rel (e.g. theme-only images) gets a synthetic key; it never becomes a relationship.

The content type is derived from the file extension; the extension mapping is wider than the registry's Default entries (bmp, tiff, svg) and preserved verbatim from the historic load path.

Constant Summary collapse

CONTENT_TYPES =

Extension → content type mapping (wider than the registry's Default entries; preserved verbatim from the historic load path).

{
  "jpg" => "image/jpeg", "jpeg" => "image/jpeg",
  "png" => "image/png", "gif" => "image/gif",
  "bmp" => "image/bmp",
  "tiff" => "image/tiff", "tif" => "image/tiff",
  "svg" => "image/svg+xml"
}.freeze

Instance Method Summary collapse

Instance Method Details

#load(context, definition) ⇒ void

This method returns an undefined value.

Parameters:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/uniword/docx/part_loader/image_loader.rb', line 33

def load(context, definition)
  package = context.package
  return unless package.document

  paths = context.matching_paths(definition)
  return if paths.empty?

  paths.each do |path|
    load_image(context, definition, path)
  end
end