why is that any call to a m:template function that does not generate anything (i.e. its result is an empty string) still leaves an empty line in the generated document? This is an issue if a m:template is used to include optional parts of the document which may not be present e.g. because the corresponding model element is missing or a certain value is null. br, M,
Yes, your test is certainly correct, but isn´t it somewhat unrealistic? In our templates there is mostly one m2doc field per line - also in template definition. Otherwise the template code would become sheer unreadable. So the general question is, when the line contains just a m2doc field and no other characters (except newline), what should m2doc do? I think nothing should be included in the generated document. Or at least this behaviour should be configurable via a parameter.
It works for m:comment, which does not leave an empty line behind, but seemingly it does not work for a call to m:template.
I’m not even sure what the change should be, white space management is not a simple task. also it would break existing templates so it can only be included in a major release. It also need to be in the language not an option. And ideally it should be the same mechanism as Acceleo 4 (see caseExpressionStatement() and caseTextStatement()).
In the end it night not be a big patch, and tests already exists for those cases so you can give it a try. The first step will be to open an issue.
Understood. The Acceleo code is not self-explanatory (e.g. the semantics of
isNewLineNeeded() etc.), so w/o a lengthy analysis of it I cannot support you. But the logic would be simple: if the result is an empty line where previously there were m2doc fields on it, that empty line would not be included into the document.
Yes maybe I overthink the problem because of my experience… but I don’t want to change his without more reflection and since it will be a breaking change I have more time to think about it until the next major release.
Did you try to remove the first and last new line in your template ? Even if it make the code ugly, it can be a workaround in the mean time.
Unfortunately, even after I removed all newlines fro mthe template definition, no change in the generated document.
And, after eyeballing the code you have referred to, it may be the code is not optimal e.g. the single responsibility principle is not really followed, so I think you are right, it might be difficult to find out what changes need to be done exactly.
Hi, this issue has some importance and urgency fo us, because e.g. when generating chapters on model elements that might have multiple optional fields ( like state transitions: summary, descriptions, guards, effects…) using templates such as “m:template writeNonEmptyStringWithPrefix(str: String, prefix: String)” we end up with some chapters containing groups of many empty lines. To work around this using Word macros for postprocessing would be ugly (the templates would leave delimited text like <> behind to tag the lines which the macro would then delete). You have scheduled this bug for m2doc 4.0.0, but there is still no due date. Will it be released this year? br, Marek