9
9
from reactpy_django import config
10
10
from reactpy_django .templatetags .reactpy import component
11
11
12
+ #
13
+ # Point to our non-Django analogue.
14
+ #
15
+ DJT_TEMPLATE = "reactpy/component.html"
16
+
12
17
13
18
class ReactPyExtension (Extension ):
14
19
"""
@@ -17,7 +22,7 @@ class ReactPyExtension(Extension):
17
22
18
23
{{ component(*args, **kwargs) }}
19
24
"""
20
- DJT_TEMPLATE = 'reactpy/component.html'
25
+
21
26
#
22
27
# Therefore, there is no new tag to parse().
23
28
#
@@ -31,7 +36,9 @@ def __init__(self, environment):
31
36
environment .globals ["component" ] = self .template_tag
32
37
33
38
@pass_context
34
- def template_tag (self , jinja_context : Context , dotted_path : str , * args , ** kwargs ) -> str :
39
+ def template_tag (
40
+ self , jinja_context : Context , dotted_path : str , * args , ** kwargs
41
+ ) -> str :
35
42
"""
36
43
This method is used to embed an existing ReactPy component into your
37
44
Jinja2 template.
@@ -46,9 +53,14 @@ def template_tag(self, jinja_context: Context, dotted_path: str, *args, **kwargs
46
53
Returns:
47
54
Whatever the components returns.
48
55
"""
49
- django_context = RequestContext (jinja_context .parent ['request' ], autoescape = jinja_context .eval_ctx .autoescape )
56
+ django_context = RequestContext (
57
+ jinja_context .parent ["request" ],
58
+ autoescape = jinja_context .eval_ctx .autoescape ,
59
+ )
50
60
template_context = component (django_context , dotted_path , * args , ** kwargs )
51
61
#
52
62
# TODO: can this be usefully cached?
53
63
#
54
- return loader .render_to_string (self .DJT_TEMPLATE , template_context , jinja_context .parent ['request' ])
64
+ return loader .render_to_string (
65
+ DJT_TEMPLATE , template_context , jinja_context .parent ["request" ]
66
+ )
0 commit comments