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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
Directives: Import, Inheritance, Declaration and Assignment
===========================================================
#import and #from
-----------------
The template:
::
#import math
This construct does not produce any output.
The generated module, at the bottom of the import section:
::
import math
#extends
--------
The template:
::
#extends SomeClass
The generated import (skipped if {SomeClass} has already been
imported):
::
from SomeClass import SomeClass
The generated class:
::
class x(SomeClass):
#implements
-----------
The template:
::
#implements doOutput
In the generated class, the main method is {.doOutput} instead of
{.respond}, and the attribute naming this method is:
::
_mainCheetahMethod_for_x2= 'doOutput'
#set and #set global
--------------------
The template:
::
#set $namesList = ['Moe','Larry','Curly']
$namesList
#set global $toes = ['eeny', 'meeny', 'miney', 'moe']
$toes
The output:
::
['Moe', 'Larry', 'Curly']
['eeny', 'meeny', 'miney', 'moe']
The generated code:
::
1 namesList = ['Moe','Larry','Curly']
2 write(filter(namesList)) # generated from '$namesList' at line 2, col 1.
3 write('\n')
4 globalSetVars["toes"] = ['eeny', 'meeny', 'miney', 'moe']
5 write(filter(VFS(SL,"toes",1))) # generated from '$toes' at line 4, col 1.
6 write('\n')
{globalSetVars} is a local variable referencing {.\_globalSetVars}.
Writes go into it directly, but reads take advantage of the fact
that {.\_globalSetVars} is on the searchList. (In fact, it's the
very first namespace.)
#del
----
The template:
::
#set $a = 1
#del $a
#set $a = 2
#set $arr = [0, 1, 2]
#del $a, $arr[1]
In the generated class:
::
1 a = 1
2 del a
3 a = 2
4 arr = [0, 1, 2]
5 del a, arr[1]
#attr
-----
The template:
::
#attr $namesList = ['Moe', 'Larry', 'Curly']
In the generated class:
::
## GENERATED ATTRIBUTES
namesList = ['Moe', 'Larry', 'Curly']
#def
----
The template:
::
#def printArg($arg)
The argument is $arg.
#end def
My method returned $printArg(5).
The output:
::
My method returned The argument is 5.
.
Hmm, not exactly what we expected. The method returns a trailing
newline because we didn't end the last line with {#slurp}. So the
second period (outside the method) appears on a separate line.
The {#def} generates a method {.printArg} whose structure is
similar to the main method:
::
def printArg(self,
arg,
trans=None,
dummyTrans=False,
VFS=valueFromSearchList,
VFN=valueForName,
getmtime=getmtime,
currentTime=time.time):
"""
Generated from #def printArg($arg) at line 1, col 1.
"""
if not trans:
trans = DummyTransaction()
dummyTrans = True
write = trans.response().write
SL = self._searchList
filter = self._currentFilter
globalSetVars = self._globalSetVars
########################################
## START - generated method body
write('The argument is ')
write(filter(arg)) # generated from '$arg' at line 2, col 17.
write('.\n')
########################################
## END - generated method body
if dummyTrans:
return trans.response().getvalue()
else:
return ""
When {.printArg} is called from a placeholder, only the arguments
the user supplied are passed. The other arguments retain their
default values.
#block
------
The template:
::
#block content
This page is under construction.
#end block
The output:
::
This page is under construction.
This construct generates a method {.content} in the same structure
as {.printArg} above, containing the write code:
::
write('This page is under construction.\n')
In the main method, the write code is:
::
self.content(trans=trans) # generated from ('content', '#block content')
# at line 1, col 1.
So a block placeholder implicitly passes the current transaction to
the method.
|