Class: Uniword::Ooxml::ThmxPackage
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Ooxml::ThmxPackage
- Defined in:
- lib/uniword/ooxml/thmx_package.rb
Overview
THMX Package - Word Theme format
Represents .thmx (theme) files, which are standalone theme packages. Unlike DOCX/DOTX, THMX contains ONLY a theme1.xml file.
This is the CORRECT OOP approach:
-
ONE model class for the container
-
Theme as the sole content attribute
-
No serializer/deserializer anti-pattern
Instance Attribute Summary collapse
-
#theme ⇒ Object
Access theme.
Class Method Summary collapse
-
.from_file(path) ⇒ Theme
Load THMX package from file.
-
.from_zip_content(zip_content) ⇒ ThmxPackage
Create package from extracted ZIP content.
-
.supported_extensions ⇒ Array<String>
Get supported file extensions.
-
.to_file(theme, path) ⇒ Object
Save theme to file.
Instance Method Summary collapse
-
#to_zip_content ⇒ Hash
Generate ZIP content hash.
Instance Attribute Details
#theme ⇒ Object
Access theme
57 58 59 |
# File 'lib/uniword/ooxml/thmx_package.rb', line 57 def theme @theme end |
Class Method Details
.from_file(path) ⇒ Theme
Load THMX package from file
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/uniword/ooxml/thmx_package.rb', line 31 def self.from_file(path) # Extract ZIP content extractor = Infrastructure::ZipExtractor.new zip_content = extractor.extract(path) # Parse package package = from_zip_content(zip_content) # Return theme directly (NOT a Document!) package.theme || Theme.new end |
.from_zip_content(zip_content) ⇒ ThmxPackage
Create package from extracted ZIP content
47 48 49 50 51 52 53 54 |
# File 'lib/uniword/ooxml/thmx_package.rb', line 47 def self.from_zip_content(zip_content) package = new # Parse theme (the only content) package.theme = Theme.from_xml(zip_content["theme/theme/theme1.xml"]) if zip_content["theme/theme/theme1.xml"] package end |
.supported_extensions ⇒ Array<String>
Get supported file extensions
62 63 64 |
# File 'lib/uniword/ooxml/thmx_package.rb', line 62 def self.supported_extensions [".thmx"] end |
.to_file(theme, path) ⇒ Object
Save theme to file
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/uniword/ooxml/thmx_package.rb', line 70 def self.to_file(theme, path) # Create package package = new package.theme = theme # Generate ZIP content zip_content = package.to_zip_content # Add required OOXML infrastructure files add_required_files(zip_content) # Package and save packager = Infrastructure::ZipPackager.new packager.package(zip_content, path) end |
Instance Method Details
#to_zip_content ⇒ Hash
Generate ZIP content hash
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/uniword/ooxml/thmx_package.rb', line 89 def to_zip_content content = {} # Serialize theme (the only content) if theme content["theme/theme/theme1.xml"] = theme.to_xml(encoding: "UTF-8") end content end |