Browse files

Comment.

  • Loading branch information...
1 parent e0185c3 commit 55de2dbea25917c13e6642484a06b34a8983432b hierro committed Jun 23, 2002
Showing with 50 additions and 25 deletions.
  1. +18 −21 TODO
  2. +32 −4 src/Utils/Misc.py
View
39 TODO
@@ -126,33 +126,30 @@ Cheetah command revamp
cheetah-fill etc if desired.
-#wrapper
+#entry $func($arg1, $arg2="default", $**kw)
===============================================================================
-Goal: make it more convenient to use templates in programs by providing a
-wrapper function in the .py template module. The function specifies how
-many arguments it needs and creates a searchList based on those arguments.
-New directives: #wrapper, ##doc-wrapper:, #*doc-wrapper: ... *#
-Usage: #wrapper $func($arg1, $arg2="default", ...)
-This example creates the following function in the .py template module:
- def func(arg1, arg2="default", ...):
+Make a wrapper function in the .py template module that builds a searchList
+from its positional arguments, then instantiates and fills a template and
+returns the result. The preceding example would create a function thus:
+ def func(arg1, arg2="default", searchList=None, **kw):
"""Function docstring."""
- sl = {'arg1': arg1, 'arg2': arg2, ...}
- t = TheTemplate(searchList=[sl])
+ sl = {'arg1': arg1, 'arg2': arg2}
+ if searchList is None:
+ searchList = [sl]
+ elif type(searchList) == types.ListType:
+ searchList.insert(0, sl)
+ else:
+ raise TypeError("arg 'searchList'")
+ t = TheTemplate(searchList=searchList, **kw)
return str(t)
-The doc-wrapper directives append the text to the #wrapper's docstring.
+##doc-entry: and #*doc-entry: comments are appended to the function docstring.
Finally, make this function accessible directly from the shell.
If there are any non-option arguments on the command line, call the function
instead of filling the template the normal way.
- There should be only one #wrapper per template. We could allow
-multiple if there's a demand, but #wrapper is mainly intended for templates
-that want to be called one particular way. If we do have multiple functions,
-we'd need a rule that doc-wrapper's apply to the previous function, and the
-shell command line would have to specify the function name, either as
- template.py -w func "arg1" "arg2"
-or template.py func "arg1" "arg2"
-In the latter case, the function name would always have to be specified,
-which I think is undesired.
- Should it be called #wrapper, #access, #entry, etc?
+ This would perhaps make more sense as arguments to .respond(). But
+.respond() has that pesky 'trans' argument that mustn't be interfered with,
+and other programs may assume .respond() takes only one argument. Also,
+when called via str(), str() cannot take arguments.
Upload File
View
36 src/Utils/Misc.py
@@ -1,18 +1,46 @@
#!/usr/bin/env python
-# $Id: Misc.py,v 1.3 2002/04/06 21:29:33 hierro Exp $
+# $Id: Misc.py,v 1.4 2002/06/23 19:32:10 hierro Exp $
"""Miscellaneous functions/objects used by Cheetah but also useful standalone.
Meta-Data
================================================================================
Author: Mike Orr <iron@mso.oz.net>
License: This software is released for unlimited distribution under the
terms of the Python license.
-Version: $Revision: 1.3 $
+Version: $Revision: 1.4 $
Start Date: 2001/11/07
-Last Revision Date: $Date: 2002/04/06 21:29:33 $
+Last Revision Date: $Date: 2002/06/23 19:32:10 $
"""
__author__ = "Mike Orr <iron@mso.oz.net>"
-__revision__ = "$Revision: 1.3 $"[11:-2]
+__revision__ = "$Revision: 1.4 $"[11:-2]
+
+##################################################
+## DEPENDENCIES
+
+import types # Used in UseOrRaise.
+
+##################################################
+## PRIVATE FUNCTIONS
+
+
+##################################################
+## MISCELLANEOUS FUNCTIONS
+
+#!/usr/bin/env python
+# $Id: Misc.py,v 1.4 2002/06/23 19:32:10 hierro Exp $
+"""Miscellaneous functions/objects used by Cheetah but also useful standalone.
+
+Meta-Data
+================================================================================
+Author: Mike Orr <iron@mso.oz.net>
+License: This software is released for unlimited distribution under the
+ terms of the Python license.
+Version: $Revision: 1.4 $
+Start Date: 2001/11/07
+Last Revision Date: $Date: 2002/06/23 19:32:10 $
+"""
+__author__ = "Mike Orr <iron@mso.oz.net>"
+__revision__ = "$Revision: 1.4 $"[11:-2]
##################################################
## DEPENDENCIES

0 comments on commit 55de2db

Please sign in to comment.