[WIP] Improved cpl new templating #139

This commit is contained in:
2022-12-05 23:08:52 +01:00
parent 6b8491eea2
commit 5f10603fe5
26 changed files with 822 additions and 16 deletions

View File

@@ -0,0 +1,24 @@
from abc import ABC, abstractmethod
from cpl_cli.abc.file_template_abc import FileTemplateABC
from cpl_core.utils import String
class CodeFileTemplateABC(FileTemplateABC):
@abstractmethod
def __init__(
self,
name: str,
path: str,
code: str,
use_application_api: bool,
use_startup: bool,
use_service_providing: bool,
use_async: bool,
):
FileTemplateABC.__init__(self, name, path, code)
self._use_application_api = use_application_api
self._use_startup = use_startup
self._use_service_providing = use_service_providing
self._use_async = use_async

View File

@@ -11,6 +11,9 @@ class FileTemplateABC(ABC):
self._path = path
self._code = code
def __repr__(self):
return f'<{type(self).__name__} {self._path}{self._name}>'
@property
def name(self) -> str:
return self._name
@@ -18,11 +21,14 @@ class FileTemplateABC(ABC):
@property
def path(self) -> str:
return self._path
@path.setter
def path(self, value: str):
self._path = value
@property
def value(self) -> str:
return self.get_code()
@abstractmethod
def get_code(self) -> str:
return self._code
def get_code(self) -> str: pass

View File

@@ -15,7 +15,10 @@ class GenerateSchematicABC(FileTemplateABC):
if schematic in name.lower():
self._name = f'{String.convert_to_snake_case(name)}.py'
self._class_name = f'{String.first_to_upper(name)}{String.first_to_upper(schematic)}'
self._class_name = name
if name != '':
self._class_name = f'{String.first_to_upper(name)}{String.first_to_upper(schematic)}'
if schematic in name.lower():
self._class_name = f'{String.first_to_upper(name)}'
@@ -24,7 +27,8 @@ class GenerateSchematicABC(FileTemplateABC):
return self._class_name
@abstractmethod
def get_code(self) -> str: pass
def get_code(self) -> str:
pass
@classmethod
def build_code_str(cls, code: str, **kwargs) -> str:

View File

@@ -0,0 +1,35 @@
from abc import ABC, abstractmethod
from typing import Optional
from cpl_cli.abc.file_template_abc import FileTemplateABC
from cpl_cli.configuration import WorkspaceSettings
class ProjectTypeABC(ABC):
@abstractmethod
def __init__(
self,
base_path: str,
project_name: str,
workspace: Optional[WorkspaceSettings],
use_application_api: bool,
use_startup: bool,
use_service_providing: bool,
use_async: bool,
):
self._templates: list[FileTemplateABC] = []
self._base_path = base_path
self._project_name = project_name
self._workspace = workspace
self._use_application_api = use_application_api
self._use_startup = use_startup
self._use_service_providing = use_service_providing
self._use_async = use_async
@property
def templates(self) -> list[FileTemplateABC]:
return self._templates
def add_template(self, t: FileTemplateABC):
self._templates.append(t)