Class: Uniword::Themes::ThemeImporter
- Inherits:
-
Object
- Object
- Uniword::Themes::ThemeImporter
- 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.
Instance Method Summary collapse
-
#import(thmx_path, output_path) ⇒ void
Import .thmx file to YAML.
-
#import_all(source_dir, output_dir) ⇒ Integer
Import all themes from directory.
Instance Method Details
#import(thmx_path, output_path) ⇒ void
This method returns an undefined value.
Import .thmx file to YAML
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
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 |