소스 검색

refactor a bit of code

Khaleel Al-Adhami 1 개월 전
부모
커밋
d4ac10d152
1개의 변경된 파일12개의 추가작업 그리고 16개의 파일을 삭제
  1. 12 16
      reflex/plugins/tailwind_v3.py

+ 12 - 16
reflex/plugins/tailwind_v3.py

@@ -146,6 +146,13 @@ def compile_tailwind(
     return output_path, code
 
 
+def _index_of_element_that_startswith(lines: list[str], prefix: str) -> int | None:
+    return next(
+        (i for i, line in enumerate(lines) if line.strip().startswith(prefix)),
+        None,
+    )
+
+
 def add_tailwind_to_postcss_config():
     """Add tailwind to the postcss config."""
     from reflex.constants import Dirs
@@ -161,16 +168,11 @@ def add_tailwind_to_postcss_config():
 
     postcss_file_lines = postcss_file.read_text().splitlines()
 
-    if any(line.strip().startswith("tailwindcss") for line in postcss_file_lines):
+    if _index_of_element_that_startswith(postcss_file_lines, "tailwindcss") is not None:
         return
 
-    line_with_postcss_plugins = next(
-        (
-            i
-            for i, line in enumerate(postcss_file_lines)
-            if line.strip().startswith("plugins")
-        ),
-        None,
+    line_with_postcss_plugins = _index_of_element_that_startswith(
+        postcss_file_lines, "plugins"
     )
     if not line_with_postcss_plugins:
         print(  # noqa: T201
@@ -179,15 +181,9 @@ def add_tailwind_to_postcss_config():
         )
         return
 
-    postcss_import_line = next(
-        (
-            i
-            for i, line in enumerate(postcss_file_lines)
-            if line.strip().startswith('"postcss-import"')
-        ),
-        None,
+    postcss_import_line = _index_of_element_that_startswith(
+        postcss_file_lines, '"postcss-import"'
     )
-
     postcss_file_lines.insert(
         (postcss_import_line or line_with_postcss_plugins) + 1, "tailwindcss: {},"
     )