Class: Uniword::Themes::ThemePackageReader

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/theme/theme_package_reader.rb

Overview

Reads and extracts .thmx theme package files

.thmx files are ZIP archives containing PowerPoint theme definitions with optional variant packages. The actual Word theme is nested at theme/theme/theme1.xml (not theme/theme1.xml as initially expected).

Examples:

Extract a theme package

reader = ThemePackageReader.new
files = reader.extract('Atlas.thmx')
base_theme_xml = files[:base]
variant_themes = files[:variants]

Instance Method Summary collapse

Instance Method Details

#extract(path) ⇒ Hash

Extract theme files from .thmx package

Parameters:

  • path (String)

    Path to .thmx file

Returns:

  • (Hash)

    Extracted theme data

    • :base => Base theme XML content (from theme/theme/theme1.xml)

    • :variants => Hash of variant_id => variant theme XML content

    • :variant_manager => Variant manager XML (if present)

    • :media => Hash of filename => MediaFile objects

Raises:

  • (ArgumentError)

    if file is invalid or missing required theme



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/uniword/theme/theme_package_reader.rb', line 26

def extract(path)
  extractor = Infrastructure::ZipExtractor.new
  content = extractor.extract(path)

  # Extract base theme from corrected path
  base_theme_xml = content["theme/theme/theme1.xml"]
  unless base_theme_xml
    raise ArgumentError,
          "Invalid theme package: missing theme/theme/theme1.xml"
  end

  # Extract variants
  variants = extract_variants(content)

  # Extract variant manager if present
  variant_manager_xml = content["themeVariants/themeVariantManager.xml"]

  # Extract media files
  media = extract_media_files(content)

  {
    base: base_theme_xml,
    variants: variants,
    variant_manager: variant_manager_xml,
    media: media,
  }
end