systopia / de.systopia.civioffice

Use docx files as templates to create personalized documents in various CiviCRM workflows
Other
2 stars 5 forks source link

Replace tokens by splitting text runs/paragraphs instead of replacing #62

Closed jensschuppe closed 3 months ago

jensschuppe commented 6 months ago

systopia-reference: 23739

Ad the 1.0 milestone: Let's consider this a bugfix for merging it during the beta phase.

This is still missing some things from what @dontub and @jensschuppe planned to implement:

[!NOTE]
I used a document with Live Snippets (their tokens being pre-/suffixed with text, i.e. in the middle of a paragraph) which got those values:

  • This is just some text. - should be a single Text element and get inline-inserted without styles
  • <p>This is a new paragraph</p> - should be a new paragraph (splitting the paragraph containing the token)
  • This is some text with a <strong>bold</strong> part. - should be three Text elements with styles (bold font) and get inline-inserted within the same paragraph
  • <p>This is a new paragraph with a <strong>bold</strong> part.</p> - should be a new TextRun element, creating a new paragraph (splitting the paragraph containing the token)

Note: This changes the code style of the entire TemplateProcessor.php file to comply with CiviCRM coding standards, so it's best reviewed with whitespace changes hidden.

This is also being provided as a PR to PhpWord: PHPOffice/PHPWord/pull/2607.

jensschuppe commented 6 months ago

I added a dowhile loop around the setValue() and setElementsValue() methods, since PhpWord only replaces the first occurrence of a macro variable.

jensschuppe commented 5 months ago

@pfigel as discussed, happy to receive a review on that.

dontub commented 4 months ago

@pfigel Can you check if #66 fixes all of your use cases?

dontub commented 3 months ago

@pfigel Can you check if #66 fixes all of your use cases?

Ping @pfigel

pfigel commented 3 months ago

@dontub Sorry for the delay! I re-tested the test cases above as well as some more complex templates we use in production. All scenarios work as expected now, so this LGTM. Thanks!