Cleanup
Some checks failed
Test before pr merge / test-lint (pull_request) Failing after 7s

This commit is contained in:
2025-10-16 18:19:36 +02:00
parent 98ed458d7c
commit 8ebac05dd8
3 changed files with 27 additions and 22 deletions

View File

@@ -1,5 +1,4 @@
import os import os
import re
from pathlib import Path from pathlib import Path
import click import click
@@ -10,9 +9,9 @@ from cpl.cli.model.project import Project
from cpl.cli.model.workspace import Workspace from cpl.cli.model.workspace import Workspace
from cpl.cli.utils.structure import get_project_by_name_or_path from cpl.cli.utils.structure import get_project_by_name_or_path
from cpl.cli.utils.template_collector import TemplateCollector from cpl.cli.utils.template_collector import TemplateCollector
from cpl.cli.utils.template_renderer import TemplateRenderer
from cpl.core.configuration import Configuration from cpl.core.configuration import Configuration
from cpl.core.console import Console from cpl.core.console import Console
from cpl.core.utils import String
@cli.command("generate", aliases=["g"]) @cli.command("generate", aliases=["g"])
@@ -69,7 +68,9 @@ def generate(schematic: str, name: str, verbose: bool) -> None:
Console.write_line(f"Generating {str(path / name)} ...") Console.write_line(f"Generating {str(path / name)} ...")
with open(path / f"{name}.py", "w") as f: with open(path / f"{name}.py", "w") as f:
f.write( f.write(
_render_template(schematics[schematic].split(".")[0], templates[schematics[schematic]], name, str(path)) TemplateRenderer.render_template(
schematics[schematic].split(".")[0], templates[schematics[schematic]], name, str(path)
)
) )
@@ -101,22 +102,3 @@ def _get_name_and_path_from_name(in_name: str, project: Project = None) -> tuple
selected_project = workspace.get_project_by_name(workspace.default_project) selected_project = workspace.get_project_by_name(workspace.default_project)
return (Path(selected_project.path).parent / selected_project.directory / path).resolve().absolute(), name return (Path(selected_project.path).parent / selected_project.directory / path).resolve().absolute(), name
def _render_template(schematic, template_str: str, name: str, path: str) -> str:
context = {
"schematic": schematic,
"Name": String.to_pascal_case(name),
"name": String.to_snake_case(name),
"NAME": String.to_snake_case(name).upper(),
"camelName": String.to_camel_case(name),
"multi_Name": f"{String.to_pascal_case(name)}s",
"multi_name": f"{String.to_snake_case(name)}s",
"multi_NAME": f"{String.to_snake_case(name).upper()}s",
"multi_camelName": f"{String.to_camel_case(name)}s",
"path": path.replace("\\", "/"),
}
for key, value in context.items():
template_str = template_str.replace(f"<{key}>", value)
return template_str

View File

@@ -0,0 +1,23 @@
from cpl.core.utils import String
class TemplateRenderer:
@staticmethod
def render_template(schematic, template_str: str, name: str, path: str) -> str:
context = {
"schematic": schematic,
"Name": String.to_pascal_case(name),
"name": String.to_snake_case(name),
"NAME": String.to_snake_case(name).upper(),
"camelName": String.to_camel_case(name),
"multi_Name": f"{String.to_pascal_case(name)}s",
"multi_name": f"{String.to_snake_case(name)}s",
"multi_NAME": f"{String.to_snake_case(name).upper()}s",
"multi_camelName": f"{String.to_camel_case(name)}s",
"path": path.replace("\\", "/"),
}
for key, value in context.items():
template_str = template_str.replace(f"<{key}>", value)
return template_str