Browse Source

Do nothing on empty header

master
Johann Schmitz 2 months ago
parent
commit
e13fd2692f
Signed by: ercpe <johann@j-schmitz.net> GPG Key ID: A084064277C501ED
2 changed files with 10 additions and 2 deletions
  1. +1
    -1
      j2exts/annotateblock.py
  2. +9
    -1
      tests/test_annotateblock.py

+ 1
- 1
j2exts/annotateblock.py View File

@@ -23,7 +23,7 @@ class AnnotateBlockExtension(Extension):
body = caller()
if body is None or not body.strip():
if not header or body is None or not body.strip():
return body
lines = body.split(os.linesep)


+ 9
- 1
tests/test_annotateblock.py View File

@@ -18,6 +18,10 @@ class TestAnnotateBlockExtension(object):
output = self._render("""{% annotateblock 'Some text here' %}\n \n{% endannotateblock %}""")
assert output == "\n \n"

def test_empty_header(self):
output = self._render("""{% annotateblock '' %}body text{% endannotateblock %}""")
assert output == "body text"

def test_add_annotation(self):
output = self._render("""{% annotateblock 'Some text here' %}some body{% endannotateblock %}""")
assert output == "Some text here\nsome body"
@@ -26,6 +30,10 @@ class TestAnnotateBlockExtension(object):
output = self._render("""{% annotateblock 'Some text here' %} some indented body{% endannotateblock %}""")
assert output == " Some text here\n some indented body"

def test_annoate_with_vars(self):
def test_annotate_with_vars(self):
output = self._render("""{% with prefix="# header line" %}{% annotateblock prefix %}some other text{% endannotateblock %}{%endwith%}""")
assert output == "# header line\nsome other text"

def test_annotate_with_expression(self):
output = self._render("""{% with %}{% set prefix %}# foo is {{foo}}{% endset %}{% annotateblock prefix %}some other text{% endannotateblock %}{%endwith%}""", foo='bar')
assert output == "# foo is bar\nsome other text"

Loading…
Cancel
Save