| 1 |
Comments |
| 2 |
======== |
| 3 |
|
| 4 |
|
| 5 |
Comments are used to mark notes, explanations, and decorative text |
| 6 |
that should not appear in the output. Cheetah maintains the |
| 7 |
comments in the Python module it generates from the Cheetah source |
| 8 |
code. There are two forms of the comment directive: single-line and |
| 9 |
multi-line. |
| 10 |
|
| 11 |
All text in a template definition that lies between two hash |
| 12 |
characters ({##}) and the end of the line is treated as a |
| 13 |
single-line comment and will not show up in the output, unless the |
| 14 |
two hash characters are escaped with a backslash. |
| 15 |
|
| 16 |
:: |
| 17 |
|
| 18 |
##============================= this is a decorative comment-bar |
| 19 |
$var ## this is an end-of-line comment |
| 20 |
##============================= |
| 21 |
|
| 22 |
Any text between {#\*} and {\*#} will be treated as a multi-line |
| 23 |
comment. |
| 24 |
|
| 25 |
:: |
| 26 |
|
| 27 |
#* |
| 28 |
Here is some multiline |
| 29 |
comment text |
| 30 |
*# |
| 31 |
|
| 32 |
If you put blank lines around method definitions or loops to |
| 33 |
separate them, be aware that the blank lines will be output as is. |
| 34 |
To avoid this, make sure the blank lines are enclosed in a comment. |
| 35 |
Since you normally have a comment before the next method definition |
| 36 |
(right?), you can just extend that comment to include the blank |
| 37 |
lines after the previous method definition, like so: |
| 38 |
|
| 39 |
:: |
| 40 |
|
| 41 |
#def method1 |
| 42 |
... lines ... |
| 43 |
#end def |
| 44 |
#* |
| 45 |
|
| 46 |
|
| 47 |
Description of method2. |
| 48 |
$arg1, string, a phrase. |
| 49 |
*# |
| 50 |
#def method2($arg1) |
| 51 |
... lines ... |
| 52 |
#end def |
| 53 |
|
| 54 |
Docstring Comments |
| 55 |
------------------ |
| 56 |
|
| 57 |
|
| 58 |
Python modules, classes, and methods can be documented with inline |
| 59 |
'documentation strings' (aka 'docstrings'). Docstrings, unlike |
| 60 |
comments, are accesible at run-time. Thus, they provide a useful |
| 61 |
hook for interactive help utilities. |
| 62 |
|
| 63 |
Cheetah comments can be transformed into doctrings by adding one of |
| 64 |
the following prefixes: |
| 65 |
|
| 66 |
:: |
| 67 |
|
| 68 |
##doc: This text will be added to the method docstring |
| 69 |
#*doc: If your template file is MyTemplate.tmpl, running "cheetah compile" |
| 70 |
on it will produce MyTemplate.py, with a class MyTemplate in it, |
| 71 |
containing a method .respond(). This text will be in the .respond() |
| 72 |
method's docstring. *# |
| 73 |
|
| 74 |
##doc-method: This text will also be added to .respond()'s docstring |
| 75 |
#*doc-method: This text will also be added to .respond()'s docstring *# |
| 76 |
|
| 77 |
##doc-class: This text will be added to the MyTemplate class docstring |
| 78 |
#*doc-class: This text will be added to the MyTemplate class docstring *# |
| 79 |
|
| 80 |
##doc-module: This text will be added to the module docstring MyTemplate.py |
| 81 |
#*doc-module: This text will be added to the module docstring MyTemplate.py*# |
| 82 |
|
| 83 |
Header Comments |
| 84 |
--------------- |
| 85 |
|
| 86 |
(comments.headers) Cheetah comments can also be transformed into |
| 87 |
module header comments using the following syntax: |
| 88 |
|
| 89 |
:: |
| 90 |
|
| 91 |
##header: This text will be added to the module header comment |
| 92 |
#*header: This text will be added to the module header comment *# |
| 93 |
|
| 94 |
Note the difference between {##doc-module: } and {header: }: |
| 95 |
"cheetah-compile" puts {##doc-module: } text inside the module |
| 96 |
docstring. {header: } makes the text go { above} the docstring, as |
| 97 |
a set of #-prefixed comment lines. |
| 98 |
|
| 99 |
|