Class: Uniword::Themes::ThemeVariant

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

Overview

Represents a theme variant

Theme variants provide visual style variations of a base theme. In .thmx files, variants are numbered (variant1, variant2, etc.) and each contains a complete theme definition that can override the base theme’s colors, fonts, or effects.

Examples:

Create and apply a variant

variant = ThemeVariant.new('variant2')
variant.theme_xml = variant_theme_xml_content
themed = variant.apply_to(base_theme)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, theme_xml: nil) ⇒ ThemeVariant

Initialize a theme variant

Parameters:

  • id (String)

    Variant identifier

  • theme_xml (String, nil) (defaults to: nil)

    Optional variant theme XML



33
34
35
36
37
38
# File 'lib/uniword/theme/theme_variant.rb', line 33

def initialize(id, theme_xml: nil)
  @id = id
  @theme_xml = theme_xml
  @theme = nil
  @guid = nil
end

Instance Attribute Details

#guidString?

Returns Variant GUID from theme package.

Returns:

  • (String, nil)

    Variant GUID from theme package



21
22
23
# File 'lib/uniword/theme/theme_variant.rb', line 21

def guid
  @guid
end

#idString

Returns Variant identifier (e.g., ‘variant1’, ‘variant2’).

Returns:

  • (String)

    Variant identifier (e.g., ‘variant1’, ‘variant2’)



18
19
20
# File 'lib/uniword/theme/theme_variant.rb', line 18

def id
  @id
end

#themeTheme?

Returns Parsed theme for this variant.

Returns:

  • (Theme, nil)

    Parsed theme for this variant



27
28
29
# File 'lib/uniword/theme/theme_variant.rb', line 27

def theme
  @theme
end

#theme_xmlString?

Returns Raw theme XML for this variant.

Returns:

  • (String, nil)

    Raw theme XML for this variant



24
25
26
# File 'lib/uniword/theme/theme_variant.rb', line 24

def theme_xml
  @theme_xml
end

Instance Method Details

#apply_to(base_theme) ⇒ Theme

Apply this variant to a base theme

For now, this simply returns the variant’s theme since variants in .thmx files are complete theme definitions. Future enhancement: merge variant with base theme selectively.

Parameters:

  • base_theme (Theme)

    Base theme (unused in current implementation)

Returns:

  • (Theme)

    Variant theme (or parsed variant theme)



59
60
61
62
63
64
65
66
# File 'lib/uniword/theme/theme_variant.rb', line 59

def apply_to(base_theme)
  # Parse theme if not already parsed
  parse_theme unless @theme

  # Return the variant theme
  # In .thmx files, variants are complete themes, not just overrides
  @theme || base_theme.dup
end

#inspectString

Provide detailed inspection for debugging

Returns:

  • (String)

    A readable representation of the variant



80
81
82
83
84
# File 'lib/uniword/theme/theme_variant.rb', line 80

def inspect
  "#<Uniword::Theme::ThemeVariant id=#{@id.inspect} " \
    "guid=#{@guid.inspect} " \
    "theme=#{@theme ? @theme.name : 'not parsed'}>"
end

#nameString

Get a descriptive name for this variant

Returns:

  • (String)

    Variant name



71
72
73
74
75
# File 'lib/uniword/theme/theme_variant.rb', line 71

def name
  # In the future, this could map to display names
  # For now, just return the ID
  @id
end

#parse_themeTheme

Parse the variant theme XML

Returns:

  • (Theme)

    Parsed variant theme



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

def parse_theme
  return @theme if @theme
  return nil unless @theme_xml

  parser = ThemeXmlParser.new
  @theme = parser.parse(@theme_xml)
end