Class: Idml::Composition::ImportXml
- Inherits:
-
Object
- Object
- Idml::Composition::ImportXml
- Defined in:
- lib/idml/composition/import_xml.rb
Overview
Replace text content in stories based on an XML structure tree. Walks the source XML (parsed as a typed XMLElement tree), finds matching XMLElements by Self in the package's stories, and replaces their Content text.
This implementation handles the common case: matching by Self id
and replacing the first Content run's text. Honors SimpleIDML's
simpleidml-setcontent and simpleidml-ignorecontent flags
where present (treated as opaque attribute names; no special
behavior beyond what the source XML expresses).
Instance Method Summary collapse
-
#call(xml_string:, at: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#initialize(package) ⇒ ImportXml
constructor
A new instance of ImportXml.
Constructor Details
#initialize(package) ⇒ ImportXml
Returns a new instance of ImportXml.
16 17 18 |
# File 'lib/idml/composition/import_xml.rb', line 16 def initialize(package) @package = package end |
Instance Method Details
#call(xml_string:, at: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
20 21 22 23 24 25 |
# File 'lib/idml/composition/import_xml.rb', line 20 def call(xml_string:, at: nil) # rubocop:disable Lint/UnusedMethodArgument parts = @package.each_part.to_a.to_h { |n, c| [n, c] } replacements = parse_replacements(xml_string) apply_replacements(parts, replacements) write_merged(parts) end |