File tree 3 files changed +35
-7
lines changed
3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ Using the following categories, list your changes in this order:
28
28
- ` use_query ` hook for fetching database values.
29
29
- ` use_mutation ` hook for modifying database values.
30
30
31
+ ### Fixed
32
+
33
+ - IDOM preloader is no longer sensitive to whitespace within template tags.
34
+
31
35
## [ 1.1.0] - 2022-07-01
32
36
33
37
### Added
Original file line number Diff line number Diff line change 13
13
from django_idom .config import IDOM_REGISTERED_COMPONENTS
14
14
15
15
16
- COMPONENT_REGEX = re .compile (r"{% *component +((\"[^\"']*\")|('[^\"']*'))(.*?)%}" )
17
16
_logger = logging .getLogger (__name__ )
17
+ _component_tag = r"(?P<tag>component)"
18
+ _component_path = r"(?P<path>(\"[^\"'\s]+\")|('[^\"'\s]+'))"
19
+ _component_kwargs = r"(?P<kwargs>(.*?|\s*?)*)"
20
+ COMPONENT_REGEX = re .compile (
21
+ r"{%\s*"
22
+ + _component_tag
23
+ + r"\s*"
24
+ + _component_path
25
+ + r"\s*"
26
+ + _component_kwargs
27
+ + r"\s*%}"
28
+ )
18
29
19
30
20
31
def _register_component (full_component_name : str ) -> None :
@@ -102,12 +113,12 @@ def _get_components(self, templates: set[str]) -> set[str]:
102
113
for template in templates :
103
114
with contextlib .suppress (Exception ):
104
115
with open (template , "r" , encoding = "utf-8" ) as template_file :
105
- match = COMPONENT_REGEX .findall (template_file .read ())
106
- if not match :
107
- continue
108
- components . update (
109
- [ group [ 0 ]. replace ( '"' , "" ). replace ( "'" , "" ) for group in match ]
110
- )
116
+ regex_iterable = COMPONENT_REGEX .finditer (template_file .read ())
117
+ component_paths = [
118
+ match . group ( "path" ). replace ( '"' , "" ). replace ( "'" , "" )
119
+ for match in regex_iterable
120
+ ]
121
+ components . update ( component_paths )
111
122
if not components :
112
123
_logger .warning (
113
124
"\033 [93m"
Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ def test_component_regex(self):
13
13
r"{% component 'my.component' %}" ,
14
14
r'{% component "my.component" class="my_thing" %}' ,
15
15
r'{% component "my.component" class="my_thing" attr="attribute" %}' ,
16
+ r"""{%
17
+
18
+ component
19
+ "my.component"
20
+ class="my_thing"
21
+ attr="attribute"
22
+
23
+ %}""" , # noqa: W291
16
24
}:
17
25
self .assertRegex (component , COMPONENT_REGEX )
18
26
@@ -26,5 +34,10 @@ def test_component_regex(self):
26
34
r"{%%}" ,
27
35
r" " ,
28
36
r"" ,
37
+ r'{% component " my.component " %}' ,
38
+ r"""{% component "my.component
39
+ " %}""" ,
40
+ r'{{ component """ }}' ,
41
+ r'{{ component "" }}' ,
29
42
}:
30
43
self .assertNotRegex (fake_component , COMPONENT_REGEX )
You can’t perform that action at this time.
0 commit comments