M2doc m:template calls generate empty lines

Hi,

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,

Some white space management is probably missing in M2Doc, but you should be able to generate contents from a template without any leading nor trailing new lines. You can have a look at this test.

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.

Yes I think some work can be done to improve white space management.

Is it a difficult or risky change or could it be provided by a patch?

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.

Copyright © Eclipse Capella, the Eclipse Capella logo, Eclipse and the Eclipse logo are Trademarks of The Eclipse Foundation.