Skip to content

Commit 3570737

Browse files
committed
refactor: Find layer boundaries once
1 parent 67a999f commit 3570737

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

shiny/ui/_theme.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,18 @@ def add_sass_layer_file(self: T, path: str | pathlib.Path) -> T:
417417
layer_keys = ["uses", "functions", "defaults", "mixins", "rules"]
418418
rx_pattern = re.compile(rf"^/\*--\s*scss:({'|'.join(layer_keys)})\s*--\*/$")
419419

420-
if not any([rx_pattern.match(s) for s in src]):
420+
layer_boundaries = [rx_pattern.match(line.strip()) for line in src]
421+
422+
if not any(layer_boundaries):
421423
raise ValueError(
422424
f"The file {path} doesn't contain at least one layer boundary "
423425
f"(/*-- scss:{{{','.join(layer_keys)}}} --*/)",
424426
)
425427

426428
layers: dict[str, list[str]] = {}
427429
layer_name: str = ""
428-
for line in src:
429-
layer_boundary = rx_pattern.match(line.strip())
430+
for i, line in enumerate(src):
431+
layer_boundary = layer_boundaries[i]
430432
if layer_boundary:
431433
layer_name = layer_boundary.group(1)
432434
continue

0 commit comments

Comments
 (0)