senny / sablon

Ruby Document Template Processor based on docx templates and Mail Merge fields.
MIT License
443 stars 126 forks source link

Test for re-using context for rendering #182

Closed brettwgreen closed 2 years ago

brettwgreen commented 2 years ago

This is a scenario I have where I'm generating multiple documents from the same context.

The problem is with images... unless I completely 'new up' the context or, alternatively, reload the Sablon::Content objects again into the context prior to passing to the next document, the images fail to render in subsequent renders because the IO context needs to be 'rewound'. The consequence is that the subsequent merge fields referencing those images come up blank.

I have a test here that demonstrates the problem. I was unable to find an appropriate place to add a rewind. I think there's some level of caching here so not sure the best place to put something like source.rewind if source.respond_to?(:rewind)