Skip to content

Commit

Permalink
Handle creating nested components from startunicorn. #299
Browse files Browse the repository at this point in the history
  • Loading branch information
adamghill committed Dec 18, 2021
1 parent 47893a7 commit e2af643
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions django_unicorn/management/commands/startunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,20 @@ def handle(self, *args, **options):

(component_base_path / "__init__.py").touch(exist_ok=True)

nested_paths = []

for component_name in options["component_names"]:
if "." in component_name:
(*nested_paths, component_name) = component_name.split(".")

for nested_path in nested_paths:
component_base_path /= nested_path

if not component_base_path.exists():
component_base_path.mkdir()

(component_base_path / "__init__.py").touch(exist_ok=True)

snake_case_component_name = convert_to_snake_case(component_name)
pascal_case_component_name = convert_to_pascal_case(component_name)

Expand Down Expand Up @@ -135,6 +148,12 @@ def handle(self, *args, **options):

template_base_path.mkdir()

for nested_path in nested_paths:
template_base_path /= nested_path

if not template_base_path.exists():
template_base_path.mkdir()

template_path = template_base_path / f"{component_name}.html"

if template_path.exists():
Expand Down

0 comments on commit e2af643

Please sign in to comment.