Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
d87a1107
Commit
d87a1107
authored
Mar 16, 2001
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change tal:insert to tal:content.
Also slightly refactored the starttag optimization code.
parent
236ef253
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
17 deletions
+22
-17
lib/python/TAL/TALDefs.py
lib/python/TAL/TALDefs.py
+2
-2
lib/python/TAL/TALGenerator.py
lib/python/TAL/TALGenerator.py
+20
-15
No files found.
lib/python/TAL/TALDefs.py
View file @
d87a1107
...
@@ -104,7 +104,7 @@ KNOWN_METAL_ATTRIBUTES = [
...
@@ -104,7 +104,7 @@ KNOWN_METAL_ATTRIBUTES = [
KNOWN_TAL_ATTRIBUTES
=
[
KNOWN_TAL_ATTRIBUTES
=
[
"define"
,
"define"
,
"condition"
,
"condition"
,
"
inser
t"
,
"
conten
t"
,
"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:
...
...
lib/python/TAL/TALGenerator.py
View file @
d87a1107
...
@@ -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("
inser
t
")
content = taldict.get("
conten
t
")
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
inser
t: n = n+1
if
conten
t: 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
inser
t, replace, repeat together")
raise TALError("
can
't use
conten
t, 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
inser
t:
if
conten
t:
todo["
insert"] = inser
t
todo["
content"] = conten
t
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
inser
t:
if
conten
t:
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("inser
t")
content = todo.get("conten
t")
if
inser
t:
if
conten
t:
self.emitSubstitution(
inser
t)
self.emitSubstitution(
conten
t)
self.emitEndTag(name)
self.emitEndTag(name)
repeat = todo.get("repeat")
repeat = todo.get("repeat")
if repeat:
if repeat:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment