From deb17c6c70465fd4333e1862c769d4cd200a96e2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:00:17 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../management/commands/startcomponent.py | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/django_components/management/commands/startcomponent.py b/django_components/management/commands/startcomponent.py index cb7ed595..872eb011 100644 --- a/django_components/management/commands/startcomponent.py +++ b/django_components/management/commands/startcomponent.py @@ -1,26 +1,33 @@ -from django.core.management.base import BaseCommand, CommandError -from django.conf import settings import os +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError + class Command(BaseCommand): - help = 'Creates a new component' + help = "Creates a new component" def add_arguments(self, parser): - parser.add_argument('name', type=str, help='The name of the component to create') + parser.add_argument( + "name", type=str, help="The name of the component to create" + ) def handle(self, *args, **kwargs): - name = kwargs['name'] + name = kwargs["name"] base_dir = settings.BASE_DIR - components_path = os.path.join(base_dir, f'components/{name}') + components_path = os.path.join(base_dir, f"components/{name}") - if os.path.exists(components_path): # If component directory already exists - raise CommandError(f'The component "{name}" already exists at {components_path}.') + if os.path.exists( + components_path + ): # If component directory already exists + raise CommandError( + f'The component "{name}" already exists at {components_path}.' + ) os.makedirs(components_path) - with open(components_path + '/index.js', 'w') as f: + with open(components_path + "/index.js", "w") as f: script_content = f""" window.addEventListener('load', (event) => {{ console.log("{name} component is fully loaded"); @@ -28,7 +35,7 @@ window.addEventListener('load', (event) => {{ """ f.write(script_content.strip()) - with open(components_path + '/style.css', 'w') as f: + with open(components_path + "/style.css", "w") as f: style_content = f""" .component-{name} {{ background: red; @@ -36,7 +43,7 @@ window.addEventListener('load', (event) => {{ """ f.write(style_content.strip()) - with open(components_path + '/template.html', 'w') as f: + with open(components_path + "/template.html", "w") as f: template_content = f"""
Hello from {name} component! @@ -44,7 +51,7 @@ window.addEventListener('load', (event) => {{ """ f.write(template_content.strip()) - with open(components_path + f'/{name}.py', 'w') as f: + with open(components_path + f"/{name}.py", "w") as f: py_content = f""" # In a file called [project root]/components/{name}/{name}.py from django_components import component @@ -67,4 +74,8 @@ class {name.capitalize()}(component.Component): """ f.write(py_content.strip()) - self.stdout.write(self.style.SUCCESS(f'Successfully created {name} component at {components_path}')) + self.stdout.write( + self.style.SUCCESS( + f"Successfully created {name} component at {components_path}" + ) + )