Comment nesting wasn't working properly before, where you could get
things like:
<div class="comment root" id="a">
</div> <!-- close a -->
<div class="comment" id="a/b">
<div class="comment" id="a/b/c">
<div class="comment root" id="d">
</div> <!-- close d -->
</div> <!-- close a/b/c -->
</div> <!-- close a/b -->
from a comment tree (using fake ids) of:
.
|-- a
| `-- a/b
| `-- a/b/c
`-- d
The new handling pushes the `div_close(depth)` call to the front of
the comment block, because a comment's depth tells us how many of the
already-rendered comments we need to close. Closing comments at the
top of the block means that we'll always have at least one unclosed
comment to close after the comment loop completes. With the new
handling, we'll get a more appropriate:
<div class="comment root" id="a">
<div class="comment" id="a/b">
<div class="comment" id="a/b/c">
</div> <!-- close a/b/c -->
</div> <!-- close a/b -->
</div> <!-- close a -->
<div class="comment root" id="
C29a03522-ed6e-4a9a-8823-
23a1c513865f">
</div> <!-- close d -->
Reported-by: Owen Jacobson <owen.jacobson@grimoire.ca>
{% if comments %}
{% for depth,comment in comments %}
+{{ div_close(depth) }}
{% if depth == 0 %}
<div class="comment root" id="C{{ comment_dir(comment) }}">
{% else %}
'depth':depth, 'bug': bug, 'comment':comment, 'comment_dir':comment_dir,
'format_body': format_body, 'div_close': div_close,
'strip_email': strip_email}) }}
-{{ div_close(depth) }}
{% endfor %}
-{% if comments[-1][0] > 0 %}
{{ div_close(0) }}
-{% endif %}
{% else %}
<p>No comments.</p>
{% endif %}
class _DivCloser (object):
- def __init__(self, depth=0):
+ def __init__(self, depth=-1):
self.depth = depth
def __call__(self, depth):