Commit 2fef0d4c authored by Guido van Rossum's avatar Guido van Rossum

Allow tal:repeat to be combined with tal:replace or tal:content,

repeating the substitution.

Why didn't we think of this before?!
parent 09b79ea8
...@@ -374,20 +374,16 @@ class TALGenerator: ...@@ -374,20 +374,16 @@ class TALGenerator:
fillSlot = metaldict.get("fill-slot") fillSlot = metaldict.get("fill-slot")
define = taldict.get("define") define = taldict.get("define")
condition = taldict.get("condition") condition = taldict.get("condition")
repeat = taldict.get("repeat")
content = taldict.get("content") content = taldict.get("content")
replace = taldict.get("replace") replace = taldict.get("replace")
repeat = taldict.get("repeat")
attrsubst = taldict.get("attributes") attrsubst = taldict.get("attributes")
onError = taldict.get("on-error") onError = taldict.get("on-error")
if len(metaldict) > 1: if len(metaldict) > 1:
raise METALError("at most one METAL attribute per element", raise METALError("at most one METAL attribute per element",
position) position)
n = 0 if content and replace:
if content: n = n+1 raise TALError("content and replace are mutually exclusive",
if replace: n = n+1
if repeat: n = n+1
if n > 1:
raise TALError("at most one of content, replace, repeat",
position) position)
repeatWhitespace = None repeatWhitespace = None
...@@ -425,17 +421,17 @@ class TALGenerator: ...@@ -425,17 +421,17 @@ class TALGenerator:
if condition: if condition:
self.pushProgram() self.pushProgram()
todo["condition"] = condition todo["condition"] = condition
if content: if repeat:
todo["content"] = content
elif replace:
todo["replace"] = replace
self.pushProgram()
elif repeat:
todo["repeat"] = repeat todo["repeat"] = repeat
self.emit("beginScope") self.emit("beginScope")
self.pushProgram() self.pushProgram()
if repeatWhitespace: if repeatWhitespace:
self.emitText(repeatWhitespace) self.emitText(repeatWhitespace)
if content:
todo["content"] = content
if replace:
todo["replace"] = replace
self.pushProgram()
if attrsubst: if attrsubst:
repldict = parseAttributeReplacements(attrsubst) repldict = parseAttributeReplacements(attrsubst)
for key, value in repldict.items(): for key, value in repldict.items():
...@@ -467,8 +463,8 @@ class TALGenerator: ...@@ -467,8 +463,8 @@ class TALGenerator:
useMacro = todo.get("useMacro") useMacro = todo.get("useMacro")
defineSlot = todo.get("defineSlot") defineSlot = todo.get("defineSlot")
fillSlot = todo.get("fillSlot") fillSlot = todo.get("fillSlot")
content = todo.get("content")
repeat = todo.get("repeat") repeat = todo.get("repeat")
content = todo.get("content")
replace = todo.get("replace") replace = todo.get("replace")
condition = todo.get("condition") condition = todo.get("condition")
onError = todo.get("onError") onError = todo.get("onError")
...@@ -489,11 +485,11 @@ class TALGenerator: ...@@ -489,11 +485,11 @@ class TALGenerator:
self.emitSubstitution(content, {}, position) self.emitSubstitution(content, {}, position)
if not isend: if not isend:
self.emitEndTag(name) self.emitEndTag(name)
if replace:
self.emitSubstitution(replace, repldict, position)
if repeat: if repeat:
self.emitRepeat(repeat, position) self.emitRepeat(repeat, position)
self.emit("endScope") self.emit("endScope")
if replace:
self.emitSubstitution(replace, repldict, position)
if condition: if condition:
self.emitCondition(condition) self.emitCondition(condition)
if onError: if onError:
......
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