summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@slide.com>2009-05-25 19:22:50 -0700
committerR. Tyler Ballance <tyler@slide.com>2009-05-25 19:22:50 -0700
commit9f9a217afa835d01a47248a600d42d2829884b5e (patch)
tree564233bc4fb84e94b10c79a7cfeff56dfc0b1b8b
parente401f1a70d7377d5e82d3dc5199b968e3892d0d3 (diff)
downloadpython-cheetah-9f9a217afa835d01a47248a600d42d2829884b5e.tar.gz
Working with documentation and creating a 'highlight' macro; discovering weaknesses in Cheetah's macro support
Signed-off-by: R. Tyler Ballance <tyler@slide.com>
-rw-r--r--recipes/content/Basic_Inheritance.html37
-rw-r--r--recipes/content/Basic_Inheritance.markdown16
-rw-r--r--recipes/index.tmpl41
3 files changed, 72 insertions, 22 deletions
diff --git a/recipes/content/Basic_Inheritance.html b/recipes/content/Basic_Inheritance.html
index f6f9c22..fa49199 100644
--- a/recipes/content/Basic_Inheritance.html
+++ b/recipes/content/Basic_Inheritance.html
@@ -377,15 +377,34 @@ Python.</p>
<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>
+<style type="text/css"> <!-- .code_highlighter .hll { background-color: #ffffcc }
+.code_highlighter { background: #f8f8f8; }
+.code_highlighter .c { color: #408080; font-style: italic } /* Comment */
+.code_highlighter .err { border: 1px solid #FF0000 } /* Error */
+.code_highlighter .k { color: #008000; font-weight: bold } /* Keyword */
+.code_highlighter .o { color: #666666 } /* Operator */
+.code_highlighter .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+.code_highlighter .cp { color: #BC7A00 } /* Comment.Preproc */
+.code_highlighter .c1 { color: #408080; font-style: italic } /* Comment.Single */
+.code_highlighter .cs { color: #408080; font-style: italic } /* Comment.Special */
+.code_highlighter .gd { color: #A00000 } /* Generic.Deleted */
+.code_highlighter .ge { font-style: italic } /* Generic.Emph */
+.code_highlighter .gr { color: #FF0000 } /* Generic.Error */
+.code_highlighter .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+.code_highlighter .gi { color: #00A000 } /* Generic.Inserted */
+.code_highlighter .go { color: #808080 } /* Generic.Output */
+.code_highlighter .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+.code_highlighter .gs { font-weight: bold } /* Generic.Strong */
+.code_highlighter .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+.code_highlighter .gt { color: #0040D0 } /* Generic.Traceback */
+.code_highlighter .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
+.code_highlighter .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
+.code_highlighter .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
+.code_highlighter .kp { color: #008000 } /* Keyword.Pseudo */
+.code_highlighter .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
+.code_highlighter .kt { color: #B00040 } /* Keyword.Type */
+.code_highlighter .m { color: #666666 } /* Literal.Number */
+.code_highlighter .s { color: #BA2121 } /* Literal.String
</div>
<div id="rightcontent">
diff --git a/recipes/content/Basic_Inheritance.markdown b/recipes/content/Basic_Inheritance.markdown
index 94ba5e8..15b53ac 100644
--- a/recipes/content/Basic_Inheritance.markdown
+++ b/recipes/content/Basic_Inheritance.markdown
@@ -33,10 +33,12 @@ 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'
+#highlight
+import Cheetah.Template
+
+class CookbookTemplate(Cheetah.Template.Template):
+ _page = 'Cookbook'
+ author = 'R. Tyler Ballance'
+ def pageName(self):
+ return self._page or 'Unknown'
+#end highlight
diff --git a/recipes/index.tmpl b/recipes/index.tmpl
index 769ab05..4013c77 100644
--- a/recipes/index.tmpl
+++ b/recipes/index.tmpl
@@ -1,3 +1,8 @@
+#compiler-settings
+useAutocalling=False
+useLegacyImportMode=False
+#end compiler-settings
+
#import os
#From Cheetah.Template import Template
#from Cheetah.Filters import Markdown
@@ -35,11 +40,30 @@ from the old Wiki
#end def
#def generateRecipePage(filepath)
- #set fd = $open('%s%s' % ($ExecuteContentPath, $filepath), 'r')
- #set content = $fd.readlines()
- #silent $fd.close()
+ ## Defining a highlighting function to macro-fy
+ #def _highlightMacro(src)
+ #from pygments import highlight
+ #from pygments import lexers
+ #from pygments import formatters
+ #set lexer = None
+ #try
+ #set lexer = lexers.guess_lexer(src)
+ #except lexers.ClassNotFound
+ #set lexer = lexers.PythonLexer()
+ #end try
+
+ #set formatter = formatters.HtmlFormatter(cssclass='code_highlighter')
+ #set src = highlight(src, lexer, formatter)
+ #set css = formatter.get_style_defs('.code_highlighter')
+ #return '''<style type="text/css"> <!-- %s --> </style> %s''' % (css, src)
+ #end def
+
+ ## Open and read in the .markdown document
+ #set fd = open('%s%s' % ($ExecuteContentPath, filepath), 'r')
+ #set content = fd.readlines()
+ #silent fd.close()
+
#set tmpl = Template('''
-#import Cheetah.Filters
#from Cheetah.Filters import Markdown
#import WikiRoot
#extends WikiRoot.WikiRoot
@@ -52,10 +76,15 @@ from the old Wiki
#transform Markdown
%s
#end def
- ''' % (''.join($content)), searchList=[{'PageName' : $filepath.replace('.markdown', '')}])
- #set fd = open('%s%s' % ($ExecuteContentPath, $filepath.replace('.markdown', '.html')), 'w')
+ ''' % (''.join(content)),
+ searchList=[{'PageName' : filepath.replace('.markdown', '')}],
+ compilerSettings={'macroDirectives' : {'highlight' : _highlightMacro}})
+
+ ## Write the results of the template's execution to a .html file
+ #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