implement better generic text and part of header method
This commit is contained in:
parent
ea81305e36
commit
ed491be8ca
3 changed files with 40 additions and 5 deletions
|
@ -17,11 +17,10 @@ class FormattingConfig(Config):
|
|||
self._include_repo_version: Optional[bool] = None
|
||||
self._include_repo_info_text: Optional[bool] = None
|
||||
|
||||
self._extra_header: Optional[List[str]] = None
|
||||
self._extra_header: Optional[GenericText] = None
|
||||
self._author: Optional[str] = None
|
||||
self._licenses = Optional[List[GenericText]]
|
||||
self._version: Optional[str] = None
|
||||
self._extra_header_file: Optional[GenericText] = None
|
||||
self._pytex_version: Optional[GitVersionInfo] = None
|
||||
self._pytex_info_text: Optional[GenericText] = None
|
||||
self._repo_version: Optional[GitVersionInfo] = None
|
||||
|
@ -103,9 +102,9 @@ class FormattingConfig(Config):
|
|||
return self._include_repo_info_text
|
||||
|
||||
@property
|
||||
def extra_header(self) -> list:
|
||||
def extra_header(self) -> GenericText:
|
||||
if self._extra_header is None:
|
||||
return []
|
||||
return GenericText([])
|
||||
else:
|
||||
return self._extra_header
|
||||
|
||||
|
|
|
@ -23,6 +23,15 @@ class GenericText:
|
|||
raise NotImplementedError
|
||||
return self._content
|
||||
|
||||
@text.setter
|
||||
def text(self, content: Union[List[str], Path]) -> None:
|
||||
if isinstance(content, List):
|
||||
self._content = content
|
||||
self._path = None
|
||||
else:
|
||||
self._content = None
|
||||
self._path = content
|
||||
|
||||
def format(self, **kwargs) -> str:
|
||||
for line in self._content:
|
||||
try:
|
||||
|
@ -30,3 +39,12 @@ class GenericText:
|
|||
except ValueError:
|
||||
raise NotImplementedError
|
||||
return '\n'.join(self._content)
|
||||
|
||||
def __add__(self, other):
|
||||
if isinstance(other, GenericText):
|
||||
return GenericText(self.text + other.text)
|
||||
else:
|
||||
return GenericText(self.text + other)
|
||||
|
||||
def __iadd__(self, other):
|
||||
self.text = self + other
|
||||
|
|
|
@ -5,6 +5,7 @@ from .enums import TeXType, TeXFlavour
|
|||
from .formatterif import FormatterIF
|
||||
from .generic_text import GenericText
|
||||
|
||||
|
||||
class PyTeXFormatter(FormatterIF):
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -35,5 +36,22 @@ class PyTeXFormatter(FormatterIF):
|
|||
if not(
|
||||
self.config.include_extra_header
|
||||
or self.config.include_build_time
|
||||
or self.config.include_pytex_version
|
||||
or self.config.include_pytex_info_text
|
||||
or self.config.include_repo_version
|
||||
or self.config.include_repo_info_text
|
||||
):
|
||||
pass
|
||||
self._header = GenericText([])
|
||||
else:
|
||||
self._header = GenericText([])
|
||||
# TODO: handle license
|
||||
if self.config.include_extra_header:
|
||||
self._header += self.config.extra_header + ['']
|
||||
if self.config.include_repo_info_text:
|
||||
self._header += self.config.repo_info_text
|
||||
if self.config.include_pytex_info_text:
|
||||
self._header += self.config.pytex_info_text + ['']
|
||||
|
||||
## TODO handle rest
|
||||
|
||||
return self._header
|
||||
|
|
Loading…
Reference in a new issue