Class: Uniword::Themes::ThemeImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/themes/theme_importer.rb

Overview

Imports .thmx theme files and converts them to YAML format

Provides functionality to convert Office theme packages to human-readable YAML files that can be bundled with the gem.

Examples:

Import single theme

importer = ThemeImporter.new
importer.import('Atlas.thmx', 'data/themes/atlas.yml')

Import all themes from directory

importer = ThemeImporter.new
importer.import_all('themes/', 'data/themes/')

Instance Method Summary collapse

Instance Method Details

#import(thmx_path, output_path) ⇒ void

This method returns an undefined value.

Import .thmx file to YAML

Parameters:

  • thmx_path (String)

    Path to .thmx file

  • output_path (String)

    Output YAML path



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/uniword/themes/theme_importer.rb', line 26

def import(thmx_path, output_path)
  # Load theme using existing ThemeLoader
  loader = Themes::ThemeLoader.new
  theme = loader.load(thmx_path)

  # Convert to YAML-friendly hash
  theme_data = serialize_theme(theme, thmx_path)

  # Ensure output directory exists
  FileUtils.mkdir_p(File.dirname(output_path))

  # Write YAML file
  File.write(output_path, YAML.dump(theme_data))
end

#import_all(source_dir, output_dir) ⇒ Integer

Import all themes from directory

Parameters:

  • source_dir (String)

    Directory with .thmx files

  • output_dir (String)

    Output directory for YAML files

Returns:

  • (Integer)

    Number of themes imported



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/uniword/themes/theme_importer.rb', line 46

def import_all(source_dir, output_dir)
  count = 0

  Dir.glob(File.join(source_dir, "*.thmx")).each do |thmx_file|
    theme_name = theme_name_from_file(thmx_file)
    output_file = File.join(output_dir, "#{theme_name}.yml")

    puts "Importing #{File.basename(thmx_file)} -> #{File.basename(output_file)}"
    import(thmx_file, output_file)
    count += 1
  end

  count
end