Class: Uniword::Themes::Theme

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/uniword/themes/theme.rb

Overview

Friendly Theme Model - implementation-independent, human-editable

This model provides a simplified, human-friendly YAML schema for themes. It is intentionally independent of OOXML structure, making it easy to author and edit by hand.

For Word document generation, convert to Drawingml::Theme using ThemeTransformation.to_word_theme(friendly_theme).

Examples:

Load from YAML

theme = Theme.from_yaml(File.read('atlas.yml'))

Convert to Word Theme

transformation = ThemeTransformation.new
word_theme = transformation.to_word(theme)

Create from Word Theme

friendly = transformation.from_word(word_theme)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_themesArray<String>

List all available bundled themes

Returns:

  • (Array<String>)

    Theme names



150
151
152
153
154
155
156
157
# File 'lib/uniword/themes/theme.rb', line 150

def self.available_themes
  theme_dir = File.join(__dir__, "../../../data/themes")
  return [] unless Dir.exist?(theme_dir)

  Dir.glob(File.join(theme_dir, "*.yml"))
    .map { |p| File.basename(p, ".yml") }
    .sort
end

.load(name) ⇒ Theme

Load a bundled theme by name

Parameters:

  • name (String)

    Theme name (e.g., ‘atlas’, ‘badge’)

Returns:

  • (Theme)

    Loaded theme

Raises:

  • (ArgumentError)

    if theme not found



137
138
139
140
141
142
143
144
145
# File 'lib/uniword/themes/theme.rb', line 137

def self.load(name)
  path = File.join(__dir__, "../../../data/themes", "#{name}.yml")
  unless File.exist?(path)
    raise ArgumentError,
          "Theme '#{name}' not found. Available: #{available_themes.join(', ')}"
  end

  from_yaml(File.read(path))
end

Instance Method Details

#to_word_themeDrawingml::Theme

Convert to Word Theme for document generation

Returns:



162
163
164
# File 'lib/uniword/themes/theme.rb', line 162

def to_word_theme
  ThemeTransformation.new.to_word(self)
end