Formatting

Removing extra lines

All characters inside scripts are used for generation output, including spaces, line breaks, or carriage return characters.

Template content

Actual output

Expected output

<gendoc>¶
..[for (p:Package|self.ownedElement->filter(Package)->sortedBy(name))].¶

[p.name/].¶
..[/for].¶
</gendoc>¶


...¶
Allocations.¶
...¶
Context.¶
...¶
LogicalView.¶
...¶
PhysicalView.¶
...¶
UseCases.¶
...¶

Allocations.¶
Context.¶
LogicalView.¶
PhysicalView.¶
UseCases.¶

<drop/> tag allows to remove extra lines.

Document generation is internally performed in two steps and <drop/> tag removes the WHOLE paragraph in which it is contained so it must be handled with care.

First step is to analyze the lines to get as output to understand where the extra lines come from in the template and where the <drop/> tags should be located.

Template content

Output

<gendoc>
..[for (p:Package|self.ownedElement->filter(Package)->sortedBy(name))]

[p.name/].¶
..[/for]
</gendoc>


..
Allocations.¶
..
Context.¶
..
LogicalView.¶
..
PhysicalView.¶
..
UseCases.¶
..

<gendoc><drop/>¶
..[for (p:Package|self.ownedElement->filter(Package)->sortedBy(name))].<drop/>¶

 [p.name/]¶
..[/for] .<drop/>¶
</gendoc><drop/>¶

before <drop/> handling

Final output

<drop/>¶
...<drop/>¶

Allocations.¶
...<drop/>¶
Context.¶
...<drop/>¶
LogicalView.¶
...<drop/>¶
PhysicalView.¶
...<drop/>¶
UseCases.¶
...<drop/>¶
<drop/>¶

Allocations.¶

Context.¶

LogicalView.¶

PhysicalView.¶

UseCases.¶

Removing lines with empty content

Tag <dropEmpty/> drop a paragraph if the tag content is empty.

The two following examples are equivalent:

<context model=’${model_path}’/>
<gendoc>
All comments on packages:
 [for (p:Package|Package.allInstances()->sortedBy(name))]<drop/>
  [for (c:Comment| p.ownedComment)]<drop/>

- Comment for package [p.name/]: <dropEmpty>[c._body/]</dropEmpty>
  [/for]<drop/>
 [/for]<drop/>
</gendoc>



<context model=’${model_path}’/>
<gendoc>
All comments on packages:
 [for (p:Package|Package.allInstances()->sortedBy(name))]<drop/>
  [for (c:Comment| p.ownedComment)]<drop/>
   [if (not(c._body.oclIsUndefined()))]<drop/>
- Comment for package [p.name/]: [c._body/]
   [/if]<drop/>
  [/for]<drop/>
 [/for]<drop/>
</gendoc>

Removing line breaks

Using tag <nobr/> allows to make template scripts easier to maintain, because code can be written on several paragraphs without displaying line breaks in output document, such as in the following example.

Template content

Output

<gendoc>
[for (p:Package| … )]<drop/>¶
Name: <nobr/>¶
[if ( … )]<drop/>¶
 [p.name/]
[else]<drop/>¶
 Not found
[/if]<drop/> ¶
<<Other info on package>>

[/for]<drop/>¶
</gendoc>¶

Name: Actors
Name: DeploymentView
Name: Actors
<<Other info on package>>

Name: LogicalView
<<Other info on package>>

Name: UseCaseView
<<Other info on package>>

Name: Not found
<<Other info on package>>