How to comment your own code to create documentation
You have to
comment your own code in a particular way to allow Cod2Doc to create
a documentation. Cod2Doc will interpret the commented line in the code to create
the documentation. Only comment lines correctly placed are taken into account.
Cod2Doc is able to document:
Local variables are not documented.
See the first section for a description about formatting a normal text in
description.
Formatting of normal text in description
Text in description (description of header, variables, types, functions,
inline documentation) are formatted similarly to
the source from which they are extracted. Carriage returns are assumed in the same way.
To have a continuous text in html, the special tag
";;" should be used instead of
";".
The line is considered then to be the continuation of the last one (this gives a much better
result in html).
The same rule apply with the
;+ prolongation tag: you have
to replace
;+ by
;;+ to continue on the same line.
You can also add a blank line by inserting an
empty comment line between two lines
of text.
Notice that for
inline documentation, you have also the possibility to add one
or several
empty lines (non commented) between two lines.
Here is an example:
Example:
|
Example:
Global myGlobalVar1
Global myGlobalVar2
|
And the result gives:
This text and
This text are on different lines in html.
But this text follows the last one in html.
The blank comment adds a blank line between the two paragraphs.
myGlobalVar1 |
Description:
This line is independent of the next one
This text starts a new line in html
|
myGlobalVar2 |
Description:
This line
and this line concatenate in html
|
|
It's possible to insert any
html tag in the normal text. You can thus change font, colour, insert
complex tables,... Remember also that you can change the default behaviour of html tags (like
<b> or <em>) in the
style file.
Warning: there are some
special characters that needs to be
escaped in the comments of your code.
To display the following characters properly, you will have in some cases to replace them by their
html equivalent:
- & = &
- < = <
- > = >
- " = "
Cod2Doc, like in html, does not take into account more than one space at a time. If you want
to include additional spaces between words, then you will have to use the html code
.
Notice that you shouldn't need to insert a lot of html tags! Cod2Doc does a lot for you:
it can easily insert links, email addresses, images, tables,
pre-format text,... See further in the documentation for more details.
Here is an example of the use of html tags:
Example:
|
And the result gives:
This word is red.
This text is big and this one is emphazised.
|
Description of the code
The first comments of the file are considered as a code description and will be included
in the documentation. Moreover, the first line will be used as a
summary of the code
description (in the index file index.html). Notice that if empty lines are put on the top of the
source file before the comments containing the description, these comments won't be taken into
account by Cod2Doc.
Result:
|
Description:
Short description of the code
More detailed description of the code
One more line of description
...
|
|
Constant and global variables, arrays
Structure:
Const variable1 = 1
Global variable2
Dim array1(100,100)
Global variable3 = 1
|
Cod2Doc documents constant and global variables as well as arrays. It considers that the
documentation comes
on the same line as the variable declaration.
For constant variables, their
constant value will be documented. For global variables, in
in case it has a
default value, it's also specified in the documentation.
By default, only the comment on the same line of the variable will be taken into account.
To add more lines of description, add one or several
;+ lines
immediately after the declaration of the variable.
Notice that Cod2Doc could also document several variables declared on the same line
(like "Global myVar1, myVar2").
Result:
|
variable1 |
Description:
Description of variable1
|
Constant value:
1
|
variable2 |
Description:
Description of variable2
|
array1(100,100) |
Description:
Description of array1
|
variable3 |
Description:
Description of variable3
Some more description for variable3,
again some more description for variable3
|
Default value:
1
|
|
Types
Structure:
Type TypeExample
Field field1
Field field2
Field field3
End Type
|
There is two possibilities to write a description for a type. The documentation can be before or
after the Type line at your convenience. However the priority is for code
above the
Type line. Several lines are possible for the documentation (there should be no blank line
between the description and the Type line).
The
Field lines are documented similarly to variables: the comment should be on the same line
as the Field declaration. More description can be added using the
special comment ;+.
Default values of Field are also reported.
Notice that Cod2Doc could also document several fields declared on the same line
(like "Field myVar1, myVar2").
Result:
|
TypeExample |
Description:
Description of the type
More description of the type
Again more description
|
Field description:
field1 = Description of field1
field2 = Description of field2
field3 = Description of field3
Some more description for field3,
again some more description for field3 (on the same line)
|
|
Notice also that this structure would also be correct (comments after the Type line):
Structure:
Type TypeExample
Field variable1
...
|
Functions
Structure:
Function FunctionExample(aVariable, anotherVariable, optionalVariable = 1)
Return True
End Function
|
Identically to types, there is also
two possibilities to write a description for a function.
The documentation can be before or
after the Function line at your convenience. However the priority is for code
above the
Function line. Several lines are possible for the documentation (there should be no blank line
between the description and the Function line).
The
arguments of the function are also documented, and optional arguments are put into [] with
their default values. To document argument,
two possibilities are offered. A special comment has
to be inserted in the function description:
- ; nameOfVariable = Description of the variable nameOfVariable
where nameOfVariable is the name of the concerned argument
- ; argn = Description of the argument n
where n is the index of the concerned argument in the argument list of the function
(this method has the advantage to be quick to write, but has some drawbacks in case
of argument re-ordering or in the readability of the code)
The
return value is documented also in the function description. Cod2Doc searches for a line of
this type:
- ; return = Description of the return value
If the function has no return value, Cod2Doc determines it and then specifies the return value as
"None".
More description can be added to the variable or return description using the
special comment ;+.
Of course, one of the variables (or all) or the return value may not appear in the function
description.
Result:
|
FunctionExample(aVariable, anotherVariable, [optionalVariable=1]) |
Description:
Description of the function
More description of the function
Again more description
|
Parameters:
aVariable = Description of aVariable
anotherVariable = Description of anotherVariable
More description
optionalVariable = Description of the optional variable [Default value = 1]
|
Return value:
Description of the return value
More description of the return value
|
|
Notice also that this structure would also be correct (comments after the Function line and
use of the keyword arg
n):
Structure:
Function FunctionExample(aVariable, anotherVariable, optionalVariable = 1)
Return True
End Function
|
Final remark on colours of the different categories
You can easily set
different colours for every category (global variable, functions, ...) for
a better visual differentiation. For that, you will need to modify the
style files written in
cascading style sheets.