Skip to content

Commit

Permalink
Fixed django#14502 again -- saner verbatim closing token
Browse files Browse the repository at this point in the history
Previously, the closing token for the verbatim tag was specified as the
first argument of the opening token. As pointed out by Jannis, this is
a rather major departure from the core tag standard.

The new method reflects how you can give a specific closing name to
{% block %} tags.
  • Loading branch information
SmileyChris committed Jun 18, 2012
1 parent ffa6d95 commit c57ba67
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
9 changes: 2 additions & 7 deletions django/template/base.py
Expand Up @@ -216,13 +216,8 @@ def create_token(self, token_string, in_tag):
if token_string.startswith(VARIABLE_TAG_START):
token = Token(TOKEN_VAR, token_string[2:-2].strip())
elif token_string.startswith(BLOCK_TAG_START):
if block_content.startswith('verbatim'):
bits = block_content.split(' ', 1)
if bits[0] == 'verbatim':
if len(bits) > 1:
self.verbatim = bits[1]
else:
self.verbatim = 'endverbatim'
if block_content[:9] in ('verbatim', 'verbatim '):
self.verbatim = 'end%s' % block_content
token = Token(TOKEN_BLOCK, block_content)
elif token_string.startswith(COMMENT_TAG_START):
content = ''
Expand Down
14 changes: 5 additions & 9 deletions django/template/defaulttags.py
Expand Up @@ -1291,18 +1291,14 @@ def verbatim(parser, token):
{% don't process this %}
{% endverbatim %}
You can also specify an alternate closing tag::
You can also designate a specific closing tag block (allowing the
unrendered use of ``{% endverbatim %}``)::
{% verbatim -- %}
{% verbatim myblock %}
...
{% -- %}
{% endverbatim myblock %}
"""
bits = token.contents.split(' ', 1)
if len(bits) > 1:
closing_tag = bits[1]
else:
closing_tag = 'endverbatim'
nodelist = parser.parse((closing_tag,))
nodelist = parser.parse(('endverbatim',))
parser.delete_first_token()
return VerbatimNode(nodelist.render(Context()))

Expand Down
10 changes: 5 additions & 5 deletions docs/ref/templates/builtins.txt
Expand Up @@ -1047,12 +1047,12 @@ Django's syntax. For example::
{{if dying}}Still alive.{{/if}}
{% endverbatim %}

You can also specify an alternate closing tag::
You can also designate a specific closing tag, allowing the use of
``{% endverbatim %}`` as part of the unrendered contents::

{% verbatim finished %}
The verbatim tag looks like this:
{% verbatim %}{% endverbatim %}
{% finished %}
{% verbatim myblock %}
Avoid template rendering via the {% verbatim %}{% endverbatim %} block.
{% endverbatim myblock %}

.. templatetag:: widthratio

Expand Down
2 changes: 1 addition & 1 deletion tests/regressiontests/templates/tests.py
Expand Up @@ -1623,7 +1623,7 @@ def get_template_tests(self):
'verbatim-tag03': ("{% verbatim %}It's the {% verbatim %} tag{% endverbatim %}", {}, "It's the {% verbatim %} tag"),
'verbatim-tag04': ('{% verbatim %}{% verbatim %}{% endverbatim %}{% endverbatim %}', {}, template.TemplateSyntaxError),
'verbatim-tag05': ('{% verbatim %}{% endverbatim %}{% verbatim %}{% endverbatim %}', {}, ''),
'verbatim-tag06': ("{% verbatim -- %}Don't {% endverbatim %} just yet{% -- %}", {}, "Don't {% endverbatim %} just yet"),
'verbatim-tag06': ("{% verbatim special %}Don't {% endverbatim %} just yet{% endverbatim special %}", {}, "Don't {% endverbatim %} just yet"),
}
return tests

Expand Down

0 comments on commit c57ba67

Please sign in to comment.