[Zpt] CVS: Packages/TAL - TALDefs.py:1.9 TALGenerator.py:1.11

guido@digicool.com guido@digicool.com
Fri, 16 Mar 2001 12:06:26 -0500 (EST)


Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv30963

Modified Files:
	TALDefs.py TALGenerator.py 
Log Message:
Change tal:insert to tal:content.

Also slightly refactored the starttag optimization code.



--- Updated File TALDefs.py in package Packages/TAL --
--- TALDefs.py	2001/03/16 12:17:46	1.8
+++ TALDefs.py	2001/03/16 17:06:26	1.9
@@ -104,7 +104,7 @@
 KNOWN_TAL_ATTRIBUTES = [
     "define",
     "condition",
-    "insert",
+    "content",
     "replace",
     "repeat",
     "attributes",
@@ -138,7 +138,7 @@
 def parseSubstitution(arg):
     m = _subst_re.match(arg)
     if not m:
-        print "Bad syntax in insert/replace:", `arg`
+        print "Bad syntax in replace/content:", `arg`
         return None, None
     key, expr = m.group(1, 2)
     if not key:

--- Updated File TALGenerator.py in package Packages/TAL --
--- TALGenerator.py	2001/03/16 13:18:23	1.10
+++ TALGenerator.py	2001/03/16 17:06:26	1.11
@@ -128,12 +128,12 @@
             if item[0] == "endTag":
                 collect.append("</%s>" % item[1])
                 continue
-            if item[0] == "startTag" and not item[2]:
-                collect.append("<%s>" % item[1])
-                continue
-            if item[0] == "startEndTag" and not item[2]:
-                collect.append("<%s/>" % item[1])
-                continue
+            if item[0] == "startTag":
+                if self.optimizeStartTag(collect, item[1], item[2], ">"):
+                    continue
+            if item[0] == "startEndTag":
+                if self.optimizeStartTag(collect, item[1], item[2], "/>"):
+                    continue
             text = string.join(collect, "")
             if text:
                 output.append(("rawtext", text))
@@ -143,6 +143,11 @@
             collect = []
         return output
 
+    def optimizeStartTag(self, collect, name, attrlist, end):
+        if not attrlist:
+            collect.append("<%s%s" % (name, end))
+            return 1
+
     def todoPush(self, todo):
         self.todoStack.append(todo)
 
@@ -299,7 +304,7 @@
         fillSlot = metaldict.get("fill-slot")
         defines = taldict.get("define")
         condition = taldict.get("condition")
-        insert = taldict.get("insert")
+        content = taldict.get("content")
         replace = taldict.get("replace")
         repeat = taldict.get("repeat")
         attrsubst = taldict.get("attributes")
@@ -311,11 +316,11 @@
         if n > 1:
             raise METALError("only one METAL attribute per element")
         n = 0
-        if insert: n = n+1
+        if content: n = n+1
         if replace: n + n+1
         if repeat: n = n+1
         if n > 1:
-            raise TALError("can't use insert, replace, repeat together")
+            raise TALError("can't use content, replace, repeat together")
         repeatWhitespace = None
         if repeat:
             # Hack to include preceding whitespace in the loop program
@@ -340,8 +345,8 @@
         if condition:
             self.pushProgram()
             todo["condition"] = condition
-        if insert:
-            todo["insert"] = insert
+        if content:
+            todo["content"] = content
         elif replace:
             todo["replace"] = replace
             self.pushProgram()
@@ -356,7 +361,7 @@
         else:
             repldict = {}
         self.emitStartTag(name, self.replaceAttrs(attrlist, repldict))
-        if insert:
+        if content:
             self.pushProgram()
         self.todoPush(todo)
 
@@ -366,9 +371,9 @@
             # Shortcut
             self.emitEndTag(name)
             return
-        insert = todo.get("insert")
-        if insert:
-            self.emitSubstitution(insert)
+        content = todo.get("content")
+        if content:
+            self.emitSubstitution(content)
         self.emitEndTag(name)
         repeat = todo.get("repeat")
         if repeat: