Code documentation headers (using frames)

Frames are more versatile than simply adding boxes. They can for instance also add any type of string. The following examples are using frames to realize code documentation blocks.

The following code creates a paragraph and then uses different frames to generate code documentation blocks:

  • TeX/LaTeX comments (line 8)

  • HTML comment block (line 11)

  • bash scripts (line 14)

  • bash scripts with double hashmark start (line 17)

  • classic single line comment block (as found for instance in C++ and Java, line 20)

  • classic multi-line comment block (as found for instance in C++ and Java, line 23)

  • Javadoc comment block (line 26)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
AP_Context ctx = new AP_Context();
ctx.setAlignment(TextAlignment.LEFT);
ctx.setFrameTopBottomMargin(1);
ctx.setTextTopBottomMargin(0);
AsciiParagraph ap = new AsciiParagraph(ctx);
ap.addText(new LoremIpsum().getWords(9));

ctx.setFrame(A7_Frames_Doc.latexTB());
System.out.println(ap.render(20));

ctx.setFrame(A7_Frames_Doc.htmlTB());
System.out.println(ap.render(20));

ctx.setFrame(A7_Frames_Doc.bashTB());
System.out.println(ap.render(20));

ctx.setFrame(A7_Frames_Doc.bashStart2HashTB());
System.out.println(ap.render(20));

ctx.setFrame(A7_Frames_Doc.singleLine());
System.out.println(ap.render(20));

ctx.setFrame(A7_Frames_Doc.multiLine());
System.out.println(ap.render(20));

ctx.setFrame(A7_Frames_Doc.multiLineJavaDoc());
System.out.println(ap.render(20));

The resulting output for the first setting, TeX/LaTeX, is:

%
% Lorem ipsum dolor
% sit amet, consetetur
% sadipscing elitr,
% sed
%

The resulting output for the second setting, HTML, is:

<!--                      -->
<!-- Lorem ipsum dolor    -->
<!-- sit amet, consetetur -->
<!-- sadipscing elitr,    -->
<!-- sed                  -->
<!--                      -->

The resulting output for the third setting, bash, is:

#
# Lorem ipsum dolor
# sit amet, consetetur
# sadipscing elitr,
# sed
#

The resulting output for the fourth setting, bash with double hashmark start, is:

##
## Lorem ipsum dolor
## sit amet, consetetur
## sadipscing elitr,
## sed
##

The resulting output for the fifth setting, classic single line, is:

//
// Lorem ipsum dolor
// sit amet, consetetur
// sadipscing elitr,
// sed
//

The resulting output for the sixth setting, classic multi-line is:

/*
 * Lorem ipsum dolor
 * sit amet, consetetur
 * sadipscing elitr,
 * sed
 */

The resulting output for the seventh setting, Javadoc, is:

/**
 * Lorem ipsum dolor
 * sit amet, consetetur
 * sadipscing elitr,
 * sed
 */