Class: Uniword::Docx::PartLoader
- Inherits:
-
Object
- Object
- Uniword::Docx::PartLoader
- Defined in:
- lib/uniword/docx/part_loader.rb,
lib/uniword/docx/part_loader/chart_loader.rb,
lib/uniword/docx/part_loader/image_loader.rb,
lib/uniword/docx/part_loader/load_context.rb,
lib/uniword/docx/part_loader/raw_part_loader.rb,
lib/uniword/docx/part_loader/embedding_loader.rb,
lib/uniword/docx/part_loader/xml_model_loader.rb,
lib/uniword/docx/part_loader/custom_xml_loader.rb,
lib/uniword/docx/part_loader/theme_media_loader.rb,
lib/uniword/docx/part_loader/header_footer_loader.rb
Overview
Registry-driven loader for DOCX package parts.
Replaces the former hand-written per-part sequence in Package.from_zip_content: parts load by iterating Ooxml::PartRegistry.loadable (ordered by Ooxml::PartDefinition#load_priority) and dispatching each definition to the loader strategy registered under Ooxml::PartDefinition#loader.
Open/closed: a new part kind adds a strategy class plus a register_loader call and a PartRegistry registration — this loop never changes.
Defined Under Namespace
Classes: ChartLoader, CustomXmlLoader, EmbeddingLoader, HeaderFooterLoader, ImageLoader, LoadContext, RawPartLoader, ThemeMediaLoader, XmlModelLoader
Class Method Summary collapse
-
.load(zip_content, package, zip_path: nil) ⇒ Package
Load every registered part from extracted ZIP content into the package.
-
.loader_for(key) ⇒ #load
The registered strategy.
-
.register_loader(key, strategy) ⇒ Object
Register a loader strategy under a key.
Class Method Details
.load(zip_content, package, zip_path: nil) ⇒ Package
Load every registered part from extracted ZIP content into the package.
47 48 49 50 51 52 53 54 |
# File 'lib/uniword/docx/part_loader.rb', line 47 def load(zip_content, package, zip_path: nil) context = LoadContext.new(zip_content: zip_content, package: package, zip_path: zip_path) Ooxml::PartRegistry.loadable.each do |definition| loader_for(definition.loader).load(context, definition) end package end |
.loader_for(key) ⇒ #load
Returns the registered strategy.
69 70 71 72 73 |
# File 'lib/uniword/docx/part_loader.rb', line 69 def loader_for(key) loaders.fetch(key.to_sym) do raise ArgumentError, "unknown part loader: #{key.inspect}" end end |
.register_loader(key, strategy) ⇒ Object
Register a loader strategy under a key.
62 63 64 |
# File 'lib/uniword/docx/part_loader.rb', line 62 def register_loader(key, strategy) loaders[key.to_sym] = strategy end |