A small module assembles preview text for a template from a set of fields. After a recent change, part of the input data started being processed unstably: for some input sets the preview crashes, while for others it loses some values.
TemplateRenderer.render function must accept a sequence of TemplateField and return ready strings in the same order.TemplateField variants declared in the model are supported.OptionalText:
Some with non-empty text after trim must appear in the result as label: value.Some containing only spaces and None must produce the string label: —.Tags:
label: —;, without losing elements.import example.templates.*
val fields = Seq(
PlainText("Имя", " Анна "),
OptionalText("Отдел", Some(" ")),
Tags("Роли", Seq("author", "reviewer")),
OptionalText("Город", None)
)
TemplateRenderer.render(fields)
import example.templates.*
TemplateRenderer.render(Seq(Tags("Роли", Seq())))
—.3.3.121example.templatesUse line comments to explain the problem, its impact, the fix and how to test it.