mirror of
https://github.com/django-components/django-components.git
synced 2025-08-14 11:17:59 +00:00
refactor: Patch Template.compile_nodelist with custom template parser (#908)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
8cd4b03286
commit
7ed4fd88f9
9 changed files with 810 additions and 204 deletions
|
@ -2,7 +2,9 @@ import re
|
|||
from typing import TYPE_CHECKING, Any, Dict, List
|
||||
|
||||
from django.template import Context, Node, NodeList, TemplateSyntaxError
|
||||
from django.template.base import Lexer, Parser, VariableNode
|
||||
from django.template.base import Parser, VariableNode
|
||||
|
||||
from django_components.util.template_parser import parse_template
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django_components.util.template_tag import TagParam
|
||||
|
@ -48,8 +50,7 @@ class DynamicFilterExpression:
|
|||
# Copy the Parser, and pass through the tags and filters available
|
||||
# in the current context. Thus, if user calls `{% load %}` inside
|
||||
# the expression, it won't spill outside.
|
||||
lexer = Lexer(self.expr)
|
||||
tokens = lexer.tokenize()
|
||||
tokens = parse_template(self.expr)
|
||||
expr_parser = Parser(tokens=tokens)
|
||||
expr_parser.tags = {**parser.tags}
|
||||
expr_parser.filters = {**parser.filters}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue