Commit d87a1107 authored by Guido van Rossum's avatar Guido van Rossum

Change tal:insert to tal:content.

Also slightly refactored the starttag optimization code.
parent 236ef253
...@@ -104,7 +104,7 @@ KNOWN_METAL_ATTRIBUTES = [ ...@@ -104,7 +104,7 @@ KNOWN_METAL_ATTRIBUTES = [
KNOWN_TAL_ATTRIBUTES = [ KNOWN_TAL_ATTRIBUTES = [
"define", "define",
"condition", "condition",
"insert", "content",
"replace", "replace",
"repeat", "repeat",
"attributes", "attributes",
...@@ -138,7 +138,7 @@ def parseAttributeReplacements(arg): ...@@ -138,7 +138,7 @@ def parseAttributeReplacements(arg):
def parseSubstitution(arg): def parseSubstitution(arg):
m = _subst_re.match(arg) m = _subst_re.match(arg)
if not m: if not m:
print "Bad syntax in insert/replace:", `arg` print "Bad syntax in replace/content:", `arg`
return None, None return None, None
key, expr = m.group(1, 2) key, expr = m.group(1, 2)
if not key: if not key:
......
...@@ -128,12 +128,12 @@ class TALGenerator: ...@@ -128,12 +128,12 @@ class TALGenerator:
if item[0] == "endTag": if item[0] == "endTag":
collect.append("</%s>" % item[1]) collect.append("</%s>" % item[1])
continue continue
if item[0] == "startTag" and not item[2]: if item[0] == "startTag":
collect.append("<%s>" % item[1]) if self.optimizeStartTag(collect, item[1], item[2], ">"):
continue continue
if item[0] == "startEndTag" and not item[2]: if item[0] == "startEndTag":
collect.append("<%s/>" % item[1]) if self.optimizeStartTag(collect, item[1], item[2], "/>"):
continue continue
text = string.join(collect, "") text = string.join(collect, "")
if text: if text:
output.append(("rawtext", text)) output.append(("rawtext", text))
...@@ -143,6 +143,11 @@ class TALGenerator: ...@@ -143,6 +143,11 @@ class TALGenerator:
collect = [] collect = []
return output return output
def optimizeStartTag(self, collect, name, attrlist, end):
if not attrlist:
collect.append("<%s%s" % (name, end))
return 1
def todoPush(self, todo): def todoPush(self, todo):
self.todoStack.append(todo) self.todoStack.append(todo)
...@@ -299,7 +304,7 @@ class TALGenerator: ...@@ -299,7 +304,7 @@ class TALGenerator:
fillSlot = metaldict.get("fill-slot") fillSlot = metaldict.get("fill-slot")
defines = taldict.get("define") defines = taldict.get("define")
condition = taldict.get("condition") condition = taldict.get("condition")
insert = taldict.get("insert") content = taldict.get("content")
replace = taldict.get("replace") replace = taldict.get("replace")
repeat = taldict.get("repeat") repeat = taldict.get("repeat")
attrsubst = taldict.get("attributes") attrsubst = taldict.get("attributes")
...@@ -311,11 +316,11 @@ class TALGenerator: ...@@ -311,11 +316,11 @@ class TALGenerator:
if n > 1: if n > 1:
raise METALError("only one METAL attribute per element") raise METALError("only one METAL attribute per element")
n = 0 n = 0
if insert: n = n+1 if content: n = n+1
if replace: n + n+1 if replace: n + n+1
if repeat: n = n+1 if repeat: n = n+1
if 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 repeatWhitespace = None
if repeat: if repeat:
# Hack to include preceding whitespace in the loop program # Hack to include preceding whitespace in the loop program
...@@ -340,8 +345,8 @@ class TALGenerator: ...@@ -340,8 +345,8 @@ class TALGenerator:
if condition: if condition:
self.pushProgram() self.pushProgram()
todo["condition"] = condition todo["condition"] = condition
if insert: if content:
todo["insert"] = insert todo["content"] = content
elif replace: elif replace:
todo["replace"] = replace todo["replace"] = replace
self.pushProgram() self.pushProgram()
...@@ -356,7 +361,7 @@ class TALGenerator: ...@@ -356,7 +361,7 @@ class TALGenerator:
else: else:
repldict = {} repldict = {}
self.emitStartTag(name, self.replaceAttrs(attrlist, repldict)) self.emitStartTag(name, self.replaceAttrs(attrlist, repldict))
if insert: if content:
self.pushProgram() self.pushProgram()
self.todoPush(todo) self.todoPush(todo)
...@@ -366,9 +371,9 @@ class TALGenerator: ...@@ -366,9 +371,9 @@ class TALGenerator:
# Shortcut # Shortcut
self.emitEndTag(name) self.emitEndTag(name)
return return
insert = todo.get("insert") content = todo.get("content")
if insert: if content:
self.emitSubstitution(insert) self.emitSubstitution(content)
self.emitEndTag(name) self.emitEndTag(name)
repeat = todo.get("repeat") repeat = todo.get("repeat")
if repeat: if repeat:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment