summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@slide.com>2009-05-25 18:24:34 -0700
committerR. Tyler Ballance <tyler@slide.com>2009-05-25 18:24:34 -0700
commite401f1a70d7377d5e82d3dc5199b968e3892d0d3 (patch)
tree6fad83bb04a5f59db97167a116713ba9983f65f5
parent933c1c9ca6b735ee416c2c2a740a02dd58a6c07e (diff)
downloadpython-cheetah-e401f1a70d7377d5e82d3dc5199b968e3892d0d3.tar.gz
More fleshing out of the 'recipe infrastructure'
Signed-off-by: R. Tyler Ballance <tyler@slide.com>
-rw-r--r--recipes/content/Basic_Inheritance.html34
-rw-r--r--recipes/content/Basic_Inheritance.markdown39
-rw-r--r--recipes/index.tmpl6
3 files changed, 77 insertions, 2 deletions
diff --git a/recipes/content/Basic_Inheritance.html b/recipes/content/Basic_Inheritance.html
index 8fe216d..f6f9c22 100644
--- a/recipes/content/Basic_Inheritance.html
+++ b/recipes/content/Basic_Inheritance.html
@@ -352,6 +352,40 @@ border:dashed 1px #888; padding:6px; font-size:1.1em; color:#fff;}
<div id="centercontent">
<h1>Basic Inheritance</h1>
+<h2>Introduction</h2>
+<p>Cheetah, like Python, is an object-oriented language if you so choose to
+use it in that fashion. That is to say that you can use Cheetah in with
+object-oriented principles <em>or</em> you can use Cheetah in a strictly functional
+sense, like Python, Cheetah does not place restrictions on these barriers.</p>
+<p>While Cheetah is not strictly Python, it was designed as such to interoperate,
+particularly with the notion of classes, with Python itself. In effect you can
+define Python classes that inherit and extend from Cheetah-derived classes and
+vice versa. For this, Cheetah defines a few <strong>directives</strong> (denoted with the <code>#</code>
+hash-mark) that are of some help, the most important one being the <code>#extends</code>
+directive, with others playing important roles like <code>#import</code>, <code>#attr</code> and <code>#super</code></p>
+<p>In this recipe/tutorial I intend to explain and define a few key inheritance
+patterns with Cheetah, being:</p>
+<ul>
+<li>A Cheetah Template inheriting from Python</li>
+<li>Python inheriting from a Cheetah Template</li>
+<li>Cheetah Templates and "<em>mixins</em>"</li>
+</ul>
+<p>This document also operates on the assumption that the reader is at least
+somewhat familiar with the basic tenets of object-oriented programming in
+Python.</p>
+<h2>Cheetah inheriting from Python</h2>
+<p>Whether or not you are aware of it, Cheetah templates are always inheriting from
+a Python class by default. Unless otherwise denoted, Cheetah templates are compiled
+to Python classes that subclass from the Cheetah.Template.Template class.</p>
+<pre><code>import Cheetah.Template
+
+class CookbookTemplate(Cheetah.Template.Template):
+ _page = 'Cookbook'
+ author = 'R. Tyler Ballance'
+ def pageName(self):
+ retutn self._page or 'Unknown'
+</code></pre>
+<p>End</p>
</div>
<div id="rightcontent">
diff --git a/recipes/content/Basic_Inheritance.markdown b/recipes/content/Basic_Inheritance.markdown
index 98dfc79..94ba5e8 100644
--- a/recipes/content/Basic_Inheritance.markdown
+++ b/recipes/content/Basic_Inheritance.markdown
@@ -1,3 +1,42 @@
Basic Inheritance
=================
+Introduction
+------------
+Cheetah, like Python, is an object-oriented language if you so choose to
+use it in that fashion. That is to say that you can use Cheetah in with
+object-oriented principles *or* you can use Cheetah in a strictly functional
+sense, like Python, Cheetah does not place restrictions on these barriers.
+
+While Cheetah is not strictly Python, it was designed as such to interoperate,
+particularly with the notion of classes, with Python itself. In effect you can
+define Python classes that inherit and extend from Cheetah-derived classes and
+vice versa. For this, Cheetah defines a few **directives** (denoted with the `\#`
+hash-mark) that are of some help, the most important one being the `\#extends`
+directive, with others playing important roles like `\#import`, `\#attr` and `\#super`
+
+In this recipe/tutorial I intend to explain and define a few key inheritance
+patterns with Cheetah, being:
+
+* A Cheetah Template inheriting from Python
+* Python inheriting from a Cheetah Template
+* Cheetah Templates and "*mixins*"
+
+This document also operates on the assumption that the reader is at least
+somewhat familiar with the basic tenets of object-oriented programming in
+Python.
+
+
+Cheetah inheriting from Python
+------------------------------
+Whether or not you are aware of it, Cheetah templates are always inheriting from
+a Python class by default. Unless otherwise denoted, Cheetah templates are compiled
+to Python classes that subclass from the Cheetah.Template.Template class.
+
+ import Cheetah.Template
+
+ class CookbookTemplate(Cheetah.Template.Template):
+ _page = 'Cookbook'
+ author = 'R. Tyler Ballance'
+ def pageName(self):
+ retutn self._page or 'Unknown'
diff --git a/recipes/index.tmpl b/recipes/index.tmpl
index 1e085ca..769ab05 100644
--- a/recipes/index.tmpl
+++ b/recipes/index.tmpl
@@ -39,6 +39,7 @@ from the old Wiki
#set content = $fd.readlines()
#silent $fd.close()
#set tmpl = Template('''
+#import Cheetah.Filters
#from Cheetah.Filters import Markdown
#import WikiRoot
#extends WikiRoot.WikiRoot
@@ -49,11 +50,12 @@ from the old Wiki
#def content
#transform Markdown
-$recipe
+%s
#end def
- ''', searchList=[{'PageName' : $filepath.replace('.markdown', ''), 'recipe' : ''.join($content)}])
+ ''' % (''.join($content)), searchList=[{'PageName' : $filepath.replace('.markdown', '')}])
#set fd = open('%s%s' % ($ExecuteContentPath, $filepath.replace('.markdown', '.html')), 'w')
#silent fd.write(unicode(tmpl).encode('utf-8'))
#silent fd.close()
#return True
#end def
+