#23356: Unable to create template tag which behaves similar to {% verbatim %}
-------------------------------------+-------------------------------------
Reporter: Jacob Rief | Owner: atul-
Type: | bhouraskar
Cleanup/optimization | Status: assigned
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: verbatim | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by atul-bhouraskar):
* owner: nobody => atul-bhouraskar
* status: new => assigned
Comment:
The {{{Lexer.create_token()}}} method can be greatly simplified by
removing the hard coded logic for {{{self.verbatim}}} and instead saving
the full token_string in the {{{Token}}} for tags.
Currently the {{{Lexer.create_token()}}} logic returns tokens of type
{{{TokenType.TEXT}}} if it encounters a {{{{% verbatim %}}}} tag. This
change removes this logic, ie. tokens are created as normal, instead a
simple {{{Parser.parse_verbatim()}}} method can be implemented to return
verbatim text in the parsing stage. This can be called by any tag instead
of calling {{{Parser.parse()}}}.
I've created a quick pull request
[https://github.com/django/django/pull/14686] with the above implemented -
all template tests pass.
This approach fully removes the 'special case' for the built in verbatim
tag and allows creating custom tags that need similar behaviour.
The simplified {{{Lexer.create_token()}}} should now be easier to maintain
and probably also faster than the existing code (though I haven't profiled
this).
--
Ticket URL: <https://code.djangoproject.com/ticket/23356#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.2a8075ecfb5ee64746e5979f6371ebd1%40djangoproject.com.