Skip to content

Commit

Permalink
When a string expression has more than one part, it must always check…
Browse files Browse the repository at this point in the history
… if parts are trivial (such as ``None``) and ensure that these are not output.
  • Loading branch information
malthe committed Mar 3, 2011
1 parent 5b4bcea commit 3584d83
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/chameleon/tales.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ def __call__(self, name, engine):
if len(nodes) == 1:
target = nodes[0]
else:
nodes = [
template("NODE or ''", NODE=node, mode="eval")
for node in nodes
]

target = ast.BinOp(
left=ast.Str(s="%s" * len(nodes)),
op=ast.Mod(),
Expand Down
1 change: 1 addition & 0 deletions src/chameleon/tests/inputs/007-content-interpolation.pt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<body>
${'Hello world!'}
${literal}
${None}
</body>
</html>
1 change: 1 addition & 0 deletions src/chameleon/tests/outputs/007.pt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<body>
Hello world!
<div>Hello world!</div>

</body>
</html>
2 changes: 1 addition & 1 deletion src/chameleon/tests/outputs/008.pt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<body>
None

<div class="dynamic">
static
</div>
Expand Down

0 comments on commit 3584d83

Please sign in to comment.