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