Improved cpl g templating & added custom templating #137
This commit is contained in:
1
src/cpl_cli/abc/__init__.py
Normal file
1
src/cpl_cli/abc/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# imports
|
28
src/cpl_cli/abc/file_template_abc.py
Normal file
28
src/cpl_cli/abc/file_template_abc.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class FileTemplateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, name: str, path: str, code: str):
|
||||
self._name = f'{String.convert_to_snake_case(name)}.py'
|
||||
self._path = path
|
||||
self._code = code
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self.get_code()
|
||||
|
||||
@abstractmethod
|
||||
def get_code(self) -> str:
|
||||
return self._code
|
37
src/cpl_cli/abc/generate_schematic_abc.py
Normal file
37
src/cpl_cli/abc/generate_schematic_abc.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import textwrap
|
||||
from abc import abstractmethod
|
||||
from string import Template
|
||||
|
||||
from cpl_cli.abc.file_template_abc import FileTemplateABC
|
||||
from cpl_cli.configuration.schematic_collection import SchematicCollection
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class GenerateSchematicABC(FileTemplateABC):
|
||||
|
||||
def __init__(self, name: str, schematic: str, path: str):
|
||||
FileTemplateABC.__init__(self, name, path, '')
|
||||
self._name = f'{String.convert_to_snake_case(name)}_{schematic}.py'
|
||||
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)}'
|
||||
if schematic in name.lower():
|
||||
self._class_name = f'{String.first_to_upper(name)}'
|
||||
|
||||
@property
|
||||
def class_name(self) -> str:
|
||||
return self._class_name
|
||||
|
||||
@abstractmethod
|
||||
def get_code(self) -> str: pass
|
||||
|
||||
@classmethod
|
||||
def build_code_str(cls, code: str, **kwargs) -> str:
|
||||
text = textwrap.dedent(code)
|
||||
return Template(text).substitute(**kwargs)
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def register(cls, *args):
|
||||
SchematicCollection.register(*args)
|
Reference in New Issue
Block a user