feat: format-detecting TemplateProcessor facade for .docx and .odt/.ott (#138) - #215
Merged
Merged
Conversation
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This was referenced Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the universal facade decided in #138:
TemplateProcessordetects the template format from the package content and delegates toDocumentTemplateProcessor(Word) orOdtTemplateProcessor(OpenDocument Text).DocumentTemplateProcessorandOdtTemplateProcessorare unchanged.Changes
Core/TemplateProcessor.cs(public, sealed): the same method shapes as the two processors —ProcessTemplateStream/Stream withDictionary,IReadOnlyDictionaryand JSON,byte[]without byte[]×3,ProcessTemplateFile×3,ValidateTemplate×3 — plusstatic TemplateFormat DetectFormat(Stream).Core/TemplateFormat.cs(public enum):Unknown = 0,Docx = 1,Odt = 2.Core/TemplateFormatDetector.cs(internal): reads the ZIP central directory and small entries only.mimetypeentry, with a fallback to the manifest root media type (asOdtPackagedoes).…opendocument.textand…text-template→Odt. Other ODF types (spreadsheet, presentation, text-master) →Unknown, and the error message names the media type.[Content_Types].xmldeclares a WordprocessingML main part (document, template, macro-enabled document or template) →Docx. Spreadsheets and other packages →Unknown..doc, flat.fodt) →Unknown.DetectFormatrequires a readable, seekable stream (otherwiseArgumentException). It inspects the whole package and restores the stream position.ProcessingResult.Failure("Unsupported template format: …"), and nothing is written.ValidateTemplatereturns an invalid result with one error in that case.JsonExceptionas in the other processors.Tests
TriasDev.Templify.Tests/Core/TemplateProcessorTests.cscovers:mimetypeentry, other ODF types, fodt, an xlsx-like package, random bytes, an empty stream, a zip without markers, malformed content types, position restore (also for unknown input), non-seekable input and null..ott→.odtmedia type, the Stream, byte[], File, IReadOnlyDictionary and JSON overloads, buffering of non-seekable templates, the delegate's syntax failures,ThrowException, and options applied to both formats.Local checks:
dotnet build templify.sln -c Release -p:ContinuousIntegrationBuild=truepassed. All test projects pass on every TFM (2076 core tests per TFM, including the LibreOffice round trips; Tools 42; Converter 95).dotnet format --verify-no-changesanddotnet pack(package validation against 1.8.0) passed.Public API impact
Additive (declared in
PublicAPI.Unshipped.txt):TriasDev.Templify.Core.TemplateFormat(Unknown,Docx,Odt)TriasDev.Templify.Core.TemplateProcessor: constructor, 6×ProcessTemplate, 3×ProcessTemplateFile, 3×ValidateTemplate, andstatic DetectFormat(Stream)Refs #138