From 66ea7ff841c5142053277733f92e9c3527aa7144 Mon Sep 17 00:00:00 2001
From: "R. Tyler Ballance" Refer the Python's documentation if you're unfamiliar with either
+@staticmethod or @classmethod and their uses in Python, as they
+pertain to their uses in Cheetah as well. Using @staticmethod it's
+trivial to create utility templates which are common when using
+Cheetah for web development. These utility templates might contain
+a number of small functions which generate useful snippets of markup. For example: Figure 1, util.tmpl Prior to version v2.2.0 of Cheetah, there wasn't really an easy means
+of filling templates with bunches of these small utility functions. In
+v2.2.0 however, you can decorate these methods with Figure 1.1, util.tmpl With the addition of the @staticmethod decorator, the Figure 2, index.tmpl This approach is however no means to structure anything complex,
+@staticmethod and @classmethod use in Cheetah is not meant as a
+replacement for properly structured class hierarchies (which
+Cheetah supports). That said if you are building a web application
+@staticmethod/@classmethod are quite useful for the little snippets
+of markup, etc that are needed (Google AdSense blocks, footers,
+banners, etc). Last edited: Sun May 31 18:40:24 2009 @staticmethod and @classmethod
+
+#def copyright()
+ #import time
+ © CheetahCorp, Inc. $time.strftime('%Y', time.gmtime())
+#end def
+
#@staticmethod
+and use "proper" Python syntax for calling them, fig 1 revisited:
+#@staticmethod
+#def copyright()
+ #import time
+ © CheetahCorp, Inc. $time.strftime('%Y', time.gmtime())
+#end def
+
copyright()
+function can now be used without instantiating an instance of the util
+template class. In effect:
+#from util import util
+
+<strong>This is my page</strong>
+<br/>
+<hr noshade/>
+$util.copyright()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/recipes/content/@staticmethod_and_@classmethod.markdown b/recipes/content/@staticmethod_and_@classmethod.markdown
new file mode 100644
index 0000000..de2f995
--- /dev/null
+++ b/recipes/content/@staticmethod_and_@classmethod.markdown
@@ -0,0 +1,52 @@
+@staticmethod and @classmethod
+==============================
+#set $staticmethod = '[@staticmethod](http://docs.python.org/library/functions.html#staticmethod)'
+#set $classmethod = '[@classmethod](http://docs.python.org/library/functions.html#classmethod)'
+
+Refer the Python's documentation if you're unfamiliar with either
+$staticmethod or $classmethod and their uses in Python, as they
+pertain to their uses in Cheetah as well. Using $staticmethod it's
+trivial to create *utility templates* which are common when using
+Cheetah for web development. These *utility templates* might contain
+a number of small functions which generate useful snippets of markup.
+
+For example:
+
+ \#def copyright()
+ \#import time
+ © CheetahCorp, Inc. \$time.strftime('%Y', time.gmtime())
+ \#end def
+**Figure 1, util.tmpl**
+
+Prior to version **v2.2.0** of Cheetah, there wasn't really an easy means
+of filling templates with bunches of these small utility functions. In
+**v2.2.0** however, you can decorate these methods with `\#@staticmethod`
+and use "proper" Python syntax for calling them, **fig 1** revisited:
+
+ \#@staticmethod
+ \#def copyright()
+ \#import time
+ © CheetahCorp, Inc. \$time.strftime('%Y', time.gmtime())
+ \#end def
+**Figure 1.1, util.tmpl**
+
+With the addition of the $staticmethod decorator, the `copyright()`
+function can now be used without instantiating an instance of the `util`
+template class. In effect:
+
+ \#from util import util
+
+ This is my page
+
+
+ \$util.copyright()
+**Figure 2, index.tmpl**
+
+
+This approach is however no means to structure anything complex,
+$staticmethod and $classmethod use in Cheetah is not meant as a
+replacement for properly structured class hierarchies (which
+Cheetah supports). That said if you are building a web application
+$staticmethod/$classmethod are quite useful for the little snippets
+of markup, etc that are needed (Google AdSense blocks, footers,
+banners, etc).
diff --git a/recipes/content/Basic_Inheritance.html b/recipes/content/Basic_Inheritance.html
index 213263c..1331ecd 100644
--- a/recipes/content/Basic_Inheritance.html
+++ b/recipes/content/Basic_Inheritance.html
@@ -399,7 +399,7 @@ implicitly subclassing from Cheetah.Template.Template
Figure 2. recipe1.tmpl
-Last edited: Sat May 30 12:05:40 2009
+Last edited: Sun May 31 18:40:24 2009
Figure 3. Dynamic runner.py
-Last edited: Sat May 30 12:05:40 2009
+Last edited: Sun May 31 18:40:24 2009
I'll fill this out soon enough :)
-Last edited: Sat May 30 12:05:40 2009
+Last edited: Sun May 31 18:40:24 2009
If you're really hungry for some Cheetah recipies, you can check out the out-of-date Cheetah recipes page -- cgit v1.2.1