Class: Uniword::Ooxml::StyleSetPackage
- Inherits:
-
DotxPackage
- Object
- Lutaml::Model::Serializable
- DotxPackage
- Uniword::Ooxml::StyleSetPackage
- Defined in:
- lib/uniword/ooxml/styleset_package.rb
Overview
Specialized package handler for StyleSet (.dotx) files
StyleSets are stored in .dotx Word template files with style definitions in word/styles.xml. This class bridges the package infrastructure with StyleSet model serialization.
Instance Attribute Summary collapse
-
#styleset ⇒ Object
readonly
Domain model loaded from package.
Attributes inherited from DotxPackage
Class Method Summary collapse
-
.load_from_file(path) ⇒ StyleSet
Convenience: Load StyleSet from file.
-
.save_to_file(styleset, output_path, template_path:) ⇒ String
Convenience: Save StyleSet to file.
Instance Method Summary collapse
-
#load_content ⇒ StyleSet
Load StyleSet from package.
-
#save_content(styleset) ⇒ void
Save StyleSet to package.
Methods inherited from DotxPackage
from_file, from_zip_content, supported_extensions, to_file, #to_file, #to_zip_content
Instance Attribute Details
#styleset ⇒ Object (readonly)
Domain model loaded from package
25 26 27 |
# File 'lib/uniword/ooxml/styleset_package.rb', line 25 def styleset @styleset end |
Class Method Details
.load_from_file(path) ⇒ StyleSet
Convenience: Load StyleSet from file
74 75 76 77 78 79 |
# File 'lib/uniword/ooxml/styleset_package.rb', line 74 def self.load_from_file(path) package = new(path: path) styleset = package.load_content package.cleanup styleset end |
.save_to_file(styleset, output_path, template_path:) ⇒ String
Convenience: Save StyleSet to file
Creates new .dotx package with StyleSet, using template as base.
89 90 91 92 93 94 95 96 97 |
# File 'lib/uniword/ooxml/styleset_package.rb', line 89 def self.save_to_file(styleset, output_path, template_path:) package = new(path: template_path) package.extract package.save_content(styleset) package.package(output_path) package.cleanup output_path end |
Instance Method Details
#load_content ⇒ StyleSet
Load StyleSet from package
Extracts package and parses word/styles.xml into StyleSet model. Uses existing StyleSetXmlParser for XML parsing.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/uniword/ooxml/styleset_package.rb', line 34 def load_content extract # Read styles XML styles_xml = read_styles # Parse into StyleSet using existing parser parser = StyleSets::StyleSetXmlParser.new @styleset = parser.parse(styles_xml) # Store source file reference @styleset.source_file = path @styleset end |
#save_content(styleset) ⇒ void
This method returns an undefined value.
Save StyleSet to package
Serializes StyleSet model to word/styles.xml using lutaml-model. Preserves other package files unchanged.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/uniword/ooxml/styleset_package.rb', line 58 def save_content(styleset) raise "Must extract before saving" unless extracted_dir @styleset = styleset # Serialize StyleSet to XML using lutaml-model styles_xml = serialize_styleset(styleset) # Write to package write_styles(styles_xml) end |