"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "docs/dev_guide/flowControl.rst" between
cheetah3-3.1.0.tar.gz and cheetah3-3.2.0.tar.gz

About: Cheetah3 is a template engine and code generation tool for e.g. for Web development or Java, SQL, LaTeX, form email ... (written in Python).

flowControl.rst  (cheetah3-3.1.0):flowControl.rst  (cheetah3-3.2.0)
Directives: Flow Control Directives: Flow Control
======================== ========================
(flowControl)
#for #for
---- ----
(flowControl.for)
The template: The template:
:: ::
#for $i in $range(10) #for $i in $range(10)
$i #slurp $i #slurp
#end for #end for
The output: The output:
skipping to change at line 36 skipping to change at line 32
:: ::
for i in range(10): for i in range(10):
write(filter(i)) # generated from '$i' at line 2, col 1. write(filter(i)) # generated from '$i' at line 2, col 1.
write(' ') write(' ')
#repeat #repeat
------- -------
(flowControl.repeat)
The template: The template:
:: ::
#repeat 3 #repeat 3
My bonnie lies over the ocean My bonnie lies over the ocean
#end repeat #end repeat
O, bring back my bonnie to me! O, bring back my bonnie to me!
The output: The output:
:: ::
My bonnie lies over the ocean My bonnie lies over the ocean
My bonnie lies over the ocean My bonnie lies over the ocean
My bonnie lies over the ocean My bonnie lies over the ocean
O, bring back my bonnie to me! O, bring back my bonnie to me!
(OK, so the second line should be "sea" instead of "ocean".)
The generated code: The generated code:
:: ::
for __i0 in range(3): for __i0 in range(3):
write('My bonnie lies over the ocean\n') write('My bonnie lies over the ocean\n')
write('O, bring back my bonnie to me!\n') write('O, bring back my bonnie to me!\n')
Note that a new local variable of the form {\_\_i$num} will be used Note that a new local variable of the form {\_\_i$num} will be used
for each instance of {repeat} in order to permit nesting. for each instance of {repeat} in order to permit nesting.
#while #while
------ ------
(flowControl.while)
The template: The template:
:: ::
#set $alive = True #set $alive = True
#while $alive #while $alive
I am alive! I am alive!
#set $alive = False #set $alive = False
#end while #end while
skipping to change at line 138 skipping to change at line 128
if size >= 1500: if size >= 1500:
write("It's big\n") write("It's big\n")
elif size < 1500 and size > 0: elif size < 1500 and size > 0:
write("It's small\n") write("It's small\n")
else: else:
write("It's not there\n") write("It's not there\n")
#unless #unless
------- -------
(flowControl.unless)
The template: The template:
:: ::
#set $count = 9 #set $count = 9
#unless $count + 5 > 15 #unless $count + 5 > 15
Count is in range. Count is in range.
#end unless #end unless
The output: The output:
skipping to change at line 170 skipping to change at line 158
if not (count + 5 > 15): if not (count + 5 > 15):
write('Count is in range.\n') write('Count is in range.\n')
{ Note:} There is a bug in Cheetah 0.9.13. It's forgetting the { Note:} There is a bug in Cheetah 0.9.13. It's forgetting the
parentheses in the {if} expression, which could lead to it parentheses in the {if} expression, which could lead to it
calculating something different than it should. calculating something different than it should.
#break and #continue #break and #continue
-------------------- --------------------
(flowControl.break)
The template: The template:
:: ::
#for $i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 'James', 'Joe', 'Snow'] #for $i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 'James', 'Joe', 'Snow']
#if $i == 10 #if $i == 10
#continue #continue
#end if #end if
#if $i == 'Joe' #if $i == 'Joe'
#break #break
skipping to change at line 209 skipping to change at line 195
continue continue
if i == 'Joe': if i == 'Joe':
write('') write('')
break break
write(filter(i)) # generated from '$i' at line 8, col 1. write(filter(i)) # generated from '$i' at line 8, col 1.
write(' - ') write(' - ')
#pass #pass
----- -----
(flowControl.pass)
The template: The template:
:: ::
Let's check the number. Let's check the number.
#set $size = 500 #set $size = 500
#if $size >= 1500 #if $size >= 1500
It's big It's big
#elif $size > 0 #elif $size > 0
#pass #pass
skipping to change at line 250 skipping to change at line 234
write("It's big\n") write("It's big\n")
elif size > 0: elif size > 0:
pass pass
else: else:
write('Invalid entry\n') write('Invalid entry\n')
write('Done checking the number.\n') write('Done checking the number.\n')
#stop #stop
----- -----
(flowControl.stop)
The template: The template:
:: ::
A cat A cat
#if 1 #if 1
sat on a mat sat on a mat
#stop #stop
watching a rat watching a rat
#end if #end if
skipping to change at line 288 skipping to change at line 270
if dummyTrans: if dummyTrans:
return trans.response().getvalue() return trans.response().getvalue()
else: else:
return "" return ""
write(' watching a rat\n') write(' watching a rat\n')
write('in a flat.\n') write('in a flat.\n')
#return #return
------- -------
(flowControl.return)
The template: The template:
:: ::
1 1
$test[1] $test[1]
3 3
#def test #def test
1.5 1.5
#if 1 #if 1
 End of changes. 10 change blocks. 
20 lines changed or deleted 0 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)