From e401f1a70d7377d5e82d3dc5199b968e3892d0d3 Mon Sep 17 00:00:00 2001 From: "R. Tyler Ballance" Date: Mon, 25 May 2009 18:24:34 -0700 Subject: More fleshing out of the 'recipe infrastructure' Signed-off-by: R. Tyler Ballance --- recipes/content/Basic_Inheritance.html | 34 ++++++++++++++++++++++++++ recipes/content/Basic_Inheritance.markdown | 39 ++++++++++++++++++++++++++++++ recipes/index.tmpl | 6 +++-- 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;}

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'
+
+

End

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 + -- cgit v1.2.1