"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "docs/users_guide/inheritanceEtc.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).

inheritanceEtc.rst  (cheetah3-3.1.0):inheritanceEtc.rst  (cheetah3-3.2.0)
Import, Inheritance, Declaration and Assignment Import, Inheritance, Declaration and Assignment
=============================================== ===============================================
(inheritanceEtc)
#import and #from directives #import and #from directives
---------------------------- ----------------------------
(inheritanceEtc.import)
Syntax: Syntax:
:: ::
#import MODULE_OR_OBJECT [as NAME] [, ...] #import MODULE_OR_OBJECT [as NAME] [, ...]
#from MODULE import MODULE_OR_OBJECT [as NAME] [, ...] #from MODULE import MODULE_OR_OBJECT [as NAME] [, ...]
The {#import} and {#from} directives are used to make external The {#import} and {#from} directives are used to make external
Python modules or objects available to placeholders. The syntax is Python modules or objects available to placeholders. The syntax is
identical to the import syntax in Python. Imported modules are identical to the import syntax in Python. Imported modules are
skipping to change at line 39 skipping to change at line 35
#import random, re #import random, re
#from mx import DateTime # ## Part of Egenix's mx package. #from mx import DateTime # ## Part of Egenix's mx package.
After the above imports, {$math}, {$mathModule}, {$sin}, {$cos} and After the above imports, {$math}, {$mathModule}, {$sin}, {$cos} and
{$\_sin}, {$random}, {$re} and {$DateTime} may be used in {$\_sin}, {$random}, {$re} and {$DateTime} may be used in
{$placeholders} and expressions. {$placeholders} and expressions.
#extends #extends
-------- --------
(inheritanceEtc.extends)
Syntax: Syntax:
:: ::
#extends CLASS #extends CLASS
All templates are subclasses of {Cheetah.Template.Template}. All templates are subclasses of {Cheetah.Template.Template}.
However, it's possible for a template to subclass another template However, it's possible for a template to subclass another template
or a pure Python class. This is where {#extends} steps in: it or a pure Python class. This is where {#extends} steps in: it
specifies the parent class. It's equivalent to PSP's specifies the parent class. It's equivalent to PSP's
skipping to change at line 157 skipping to change at line 151
of the site administrator, ready to use as $placeholders in any of the site administrator, ready to use as $placeholders in any
template that wants it. template that wants it.
{ Whenever you use {#extends}, you often need {#implements} too,} { Whenever you use {#extends}, you often need {#implements} too,}
as in step 2 above. Read the next section to understand what as in step 2 above. Read the next section to understand what
{#implements} is and when to use it. {#implements} is and when to use it.
#implements #implements
----------- -----------
(inheritanceEtc.implements)
Syntax: Syntax:
:: ::
#implements METHOD #implements METHOD
You can call any {#def} or {#block} method directly and get its You can call any {#def} or {#block} method directly and get its
outpt. The top-level content - all the text/placeholders/directives outpt. The top-level content - all the text/placeholders/directives
outside any {#def}/{#block} - gets concatenated and wrapped in a outside any {#def}/{#block} - gets concatenated and wrapped in a
"main method", by default {.respond()}. So if you call "main method", by default {.respond()}. So if you call
skipping to change at line 228 skipping to change at line 220
renames the method to {.writeBody()}, so you have to use renames the method to {.writeBody()}, so you have to use
{#implements respond} to change it back. Otherwise the dummy {#implements respond} to change it back. Otherwise the dummy
{.respond()} in {Cheetah.Template} is found, which outputs... {.respond()} in {Cheetah.Template} is found, which outputs...
nothing. { So if you're using {#extends} and get no output, the { nothing. { So if you're using {#extends} and get no output, the {
first} thing you should think is, first} thing you should think is,
"Do I need to add {#implements respond} somewhere?" } "Do I need to add {#implements respond} somewhere?" }
#set #set
---- ----
(inheritanceEtc.set)
Syntax: Syntax:
:: ::
#set [global] $var = EXPR #set [global] $var = EXPR
{#set} is used to create and update local variables at run time. {#set} is used to create and update local variables at run time.
The expression may be any Python expression. Remember to preface The expression may be any Python expression. Remember to preface
variable names with $ unless they're part of an intermediate result variable names with $ unless they're part of an intermediate result
in a list comprehension. in a list comprehension.
skipping to change at line 295 skipping to change at line 285
By default, {#set} variables are not visible in method calls or By default, {#set} variables are not visible in method calls or
include files unless you use the {global} attribute: {#set global include files unless you use the {global} attribute: {#set global
$var = EXPRESSION}. Global variables are visible in all methods, $var = EXPRESSION}. Global variables are visible in all methods,
nested templates and included files. Use this feature with care to nested templates and included files. Use this feature with care to
prevent surprises. prevent surprises.
#del #del
---- ----
(inheritanceEtc.del)
Syntax: Syntax:
:: ::
#del $var #del $var
{#del} is the opposite of {#set}. It deletes a { local} variable. {#del} is the opposite of {#set}. It deletes a { local} variable.
Its usage is just like Python's {del} statement: Its usage is just like Python's {del} statement:
:: ::
skipping to change at line 318 skipping to change at line 306
#del $myVar #del $myVar
#del $myVar, $myArray[5] #del $myVar, $myArray[5]
Only local variables can be deleted. There is no directive to Only local variables can be deleted. There is no directive to
delete a {#set global} variable, a searchList variable, or any delete a {#set global} variable, a searchList variable, or any
other type of variable. other type of variable.
#attr #attr
----- -----
(inheritanceEtc.attr)
Syntax: Syntax:
:: ::
#attr $var = EXPR #attr $var = EXPR
The {#attr} directive creates class attributes in the generated The {#attr} directive creates class attributes in the generated
Python class. It should be used to assign simple Python literals Python class. It should be used to assign simple Python literals
such as numbers or strings. In particular, the expression must { such as numbers or strings. In particular, the expression must {
not} depend on searchList values or {#set} variables since those not} depend on searchList values or {#set} variables since those
skipping to change at line 352 skipping to change at line 338
$title, by $author, version $version $title, by $author, version $version
If you have a library of templates derived from etexts If you have a library of templates derived from etexts
(http://www.gutenberg.org/), you can extract the titles and authors (http://www.gutenberg.org/), you can extract the titles and authors
and put them in a database (assuming the templates have been and put them in a database (assuming the templates have been
compiled into .py template modules): compiled into .py template modules):
#def #def
---- ----
(inheritanceEtc.def)
Syntax: Syntax:
:: ::
#def METHOD[(ARGUMENTS)] #def METHOD[(ARGUMENTS)]
#end def #end def
Or the one-line variation: Or the one-line variation:
:: ::
skipping to change at line 452 skipping to change at line 436
#end def #end def
Because {#def} is handled at compile time, it can appear above or Because {#def} is handled at compile time, it can appear above or
below the placeholders that call it. And if a superclass below the placeholders that call it. And if a superclass
placeholder calls a method that's overridden in a subclass, it's placeholder calls a method that's overridden in a subclass, it's
the subclass method that will be called. the subclass method that will be called.
#block ... #end block #block ... #end block
--------------------- ---------------------
(inheritanceEtc.block)
The {#block} directive allows you to mark a section of your The {#block} directive allows you to mark a section of your
template that can be selectively reimplemented in a subclass. It is template that can be selectively reimplemented in a subclass. It is
very useful for changing part of a template without having to very useful for changing part of a template without having to
copy-paste-and-edit the entire thing. The output from a template copy-paste-and-edit the entire thing. The output from a template
definition that uses blocks will be identical to the output from definition that uses blocks will be identical to the output from
the same template with the {#block ... #end block} tags removed. the same template with the {#block ... #end block} tags removed.
({ Note:} don't be confused by the generic word 'block'' in this ({ Note:} don't be confused by the generic word 'block'' in this
Guide, which means a section of code inside { any} {#TAG ... #end Guide, which means a section of code inside { any} {#TAG ... #end
TAG} pair. Thus, an if-block, for-block, def-block, block-block TAG} pair. Thus, an if-block, for-block, def-block, block-block
 End of changes. 9 change blocks. 
18 lines changed or deleted 0 lines changed or added

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