Class: Uniword::Ooxml::ThemePackage
- Inherits:
-
Object
- Object
- Uniword::Ooxml::ThemePackage
- Defined in:
- lib/uniword/ooxml/theme_package.rb
Overview
Specialized package handler for Theme (.thmx) files
Themes are stored in .thmx PowerPoint theme files with the main theme definition at theme/theme/theme1.xml. This class bridges the package infrastructure with Theme model serialization.
Instance Attribute Summary collapse
-
#extracted_content ⇒ Object
Extracted content (Hash of file paths => content).
-
#path ⇒ Object
Source file path.
-
#theme ⇒ Object
readonly
Domain model loaded from package.
Class Method Summary collapse
-
.load_from_file(path) ⇒ Theme
Convenience: Load Theme from file.
-
.save_to_file(theme, output_path, template_path:) ⇒ String
Convenience: Save Theme to file.
Instance Method Summary collapse
-
#cleanup ⇒ void
Cleanup extracted content (no-op since we use memory).
-
#extract ⇒ void
Extract ZIP package.
-
#extracted_dir ⇒ Boolean
Check if extracted.
-
#initialize(path:) ⇒ ThemePackage
constructor
Initialize with file path.
-
#load_content ⇒ Theme
Load Theme from package.
-
#package(output_path) ⇒ void
Package extracted content into ZIP file.
-
#read_theme ⇒ String
Read theme XML from extracted package.
-
#save_content(theme) ⇒ void
Save Theme to package.
Constructor Details
#initialize(path:) ⇒ ThemePackage
Initialize with file path
36 37 38 39 40 |
# File 'lib/uniword/ooxml/theme_package.rb', line 36 def initialize(path:) @path = path @extracted_content = nil @theme = nil end |
Instance Attribute Details
#extracted_content ⇒ Object
Extracted content (Hash of file paths => content)
28 29 30 |
# File 'lib/uniword/ooxml/theme_package.rb', line 28 def extracted_content @extracted_content end |
#path ⇒ Object
Source file path
25 26 27 |
# File 'lib/uniword/ooxml/theme_package.rb', line 25 def path @path end |
#theme ⇒ Object (readonly)
Domain model loaded from package
31 32 33 |
# File 'lib/uniword/ooxml/theme_package.rb', line 31 def theme @theme end |
Class Method Details
.load_from_file(path) ⇒ Theme
Convenience: Load Theme from file
132 133 134 135 136 137 |
# File 'lib/uniword/ooxml/theme_package.rb', line 132 def self.load_from_file(path) package = new(path: path) theme = package.load_content package.cleanup theme end |
.save_to_file(theme, output_path, template_path:) ⇒ String
Convenience: Save Theme to file
Creates new .thmx package with Theme, using template as base.
147 148 149 150 151 152 153 154 155 |
# File 'lib/uniword/ooxml/theme_package.rb', line 147 def self.save_to_file(theme, output_path, template_path:) package = new(path: template_path) package.extract package.save_content(theme) package.package(output_path) package.cleanup output_path end |
Instance Method Details
#cleanup ⇒ void
This method returns an undefined value.
Cleanup extracted content (no-op since we use memory)
60 61 62 |
# File 'lib/uniword/ooxml/theme_package.rb', line 60 def cleanup @extracted_content = nil end |
#extract ⇒ void
This method returns an undefined value.
Extract ZIP package
45 46 47 48 |
# File 'lib/uniword/ooxml/theme_package.rb', line 45 def extract extractor = Infrastructure::ZipExtractor.new @extracted_content = extractor.extract(@path) end |
#extracted_dir ⇒ Boolean
Check if extracted
53 54 55 |
# File 'lib/uniword/ooxml/theme_package.rb', line 53 def extracted_dir @extracted_content end |
#load_content ⇒ Theme
Load Theme from package
Extracts package and parses theme/theme/theme1.xml into Theme model. Uses lutaml-model deserialization for XML parsing.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/uniword/ooxml/theme_package.rb', line 80 def load_content extract unless @extracted_content # Read theme XML theme_xml = read_theme # Parse into Theme using lutaml-model @theme = Drawingml::Theme.from_xml(theme_xml) # Store source file reference @theme.source_file = path if @theme @theme end |
#package(output_path) ⇒ void
This method returns an undefined value.
Package extracted content into ZIP file
121 122 123 124 125 126 |
# File 'lib/uniword/ooxml/theme_package.rb', line 121 def package(output_path) raise "Must extract before packaging" unless @extracted_content packager = Infrastructure::ZipPackager.new packager.package(@extracted_content, output_path) end |
#read_theme ⇒ String
Read theme XML from extracted package
67 68 69 70 71 |
# File 'lib/uniword/ooxml/theme_package.rb', line 67 def read_theme raise "Must extract before reading" unless @extracted_content @extracted_content["theme/theme/theme1.xml"] end |
#save_content(theme) ⇒ void
This method returns an undefined value.
Save Theme to package
Serializes Theme model to theme/theme/theme1.xml using lutaml-model. Preserves media files and variants unchanged.
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/uniword/ooxml/theme_package.rb', line 103 def save_content(theme) raise "Must extract before saving" unless @extracted_content @theme = theme # Serialize Theme to XML using lutaml-model with prefix: true # to preserve namespace prefixes for cross-namespace elements theme_xml = theme.to_xml(prefix: true) # Update content hash @extracted_content["theme/theme/theme1.xml"] = theme_xml end |