Class: Uniword::Themes::ThemeLoader

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

Overview

Orchestrates theme loading from .thmx files

Coordinates between ThemePackageReader and ThemeXmlParser to load themes and their variants from .thmx packages.

Examples:

Load a theme

loader = ThemeLoader.new
theme = loader.load('Atlas.thmx')
puts theme.name
puts theme.variants.keys

Load with specific variant

theme = loader.load_with_variant('Atlas.thmx', 'variant2')
puts theme.name

Instance Method Summary collapse

Instance Method Details

#load(path) ⇒ Theme

Load theme from .thmx file

Parameters:

  • path (String)

    Path to .thmx file

Returns:

  • (Theme)

    Loaded theme with variants and media

Raises:

  • (ArgumentError)

    if file is invalid



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/uniword/theme/theme_loader.rb', line 25

def load(path)
  # Extract package
  reader = ThemePackageReader.new
  extracted = reader.extract(path)

  # Parse base theme
  parser = ThemeXmlParser.new
  theme = parser.parse(extracted[:base])

  # Store source file reference
  theme.source_file = path

  # Store media files
  theme.media_files = extracted[:media] || {}

  # Load variants
  theme.variants = load_variants(extracted[:variants])

  theme
end

#load_with_variant(path, variant_id) ⇒ Theme

Load theme with specific variant applied

Parameters:

  • path (String)

    Path to .thmx file

  • variant_id (String, Integer)

    Variant identifier Can be ‘variant1’, ‘variant2’, etc. or numeric 1, 2, etc.

Returns:

  • (Theme)

    Theme with variant applied

Raises:

  • (ArgumentError)

    if variant not found



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/uniword/theme/theme_loader.rb', line 53

def load_with_variant(path, variant_id)
  # Normalize variant ID
  variant_key = normalize_variant_id(variant_id)

  # Load base theme
  base_theme = load(path)

  # Get variant
  variant = base_theme.variants[variant_key]
  unless variant
    raise ArgumentError,
          "Variant '#{variant_id}' not found. " \
          "Available variants: #{base_theme.variants.keys.join(', ')}"
  end

  # Apply variant to base theme
  variant.apply_to(base_theme)
end