fix some bugs

This commit is contained in:
Maximilian Keßler 2022-02-07 00:42:03 +01:00
parent 9d68c5cd9f
commit d1a87b5356
2 changed files with 23 additions and 5 deletions

View file

@ -73,7 +73,21 @@ class FormattingConfig(Config):
self._tex_flavour: Optional[TeXFlavour] = None self._tex_flavour: Optional[TeXFlavour] = None
def set_from_json(self, content: Dict): def set_from_json(self, content: Dict):
pass content = FormattingConfig().to_json() | content # Fill with none values
info = content[YAML_INFO]
self._author = info[YAML_AUTHOR]
self._naming_scheme = info[YAML_NAMING_SCHEME]
self._tex_flavour = info[YAML_TEX_FLAVOUR]
self._tex_type = info[YAML_TEX_TYPE]
self._description = info[YAML_DESCRIPTION]
header = content[YAML_HEADER]
extra = header[YAML_EXTRA]
self._include_extra_header = extra[YAML_INCLUDE_EXTRA_HEADER]
self._extra_header = GenericText(
extra[YAML_PATH] if extra[YAML_PATH] else extra[YAML_TEXT]
)
@classmethod @classmethod
def from_yaml(cls, content: Path): def from_yaml(cls, content: Path):
@ -111,13 +125,13 @@ class FormattingConfig(Config):
YAML_HEADER: { YAML_HEADER: {
YAML_EXTRA: { YAML_EXTRA: {
YAML_INCLUDE_EXTRA_HEADER: self._include_extra_header, YAML_INCLUDE_EXTRA_HEADER: self._include_extra_header,
YAML_PATH: self._extra_header.path if self._extra_header else None, YAML_PATH: self._extra_header.pathname if self._extra_header else None,
YAML_TEXT: self._extra_header.real_text if self._extra_header else None YAML_TEXT: self._extra_header.real_text if self._extra_header else None
}, },
YAML_REPO: { YAML_REPO: {
YAML_INCLUDE_INFO_TEXT: self._include_repo_info_text, YAML_INCLUDE_INFO_TEXT: self._include_repo_info_text,
YAML_INCLUDE_VERSION: self._include_repo_version, YAML_INCLUDE_VERSION: self._include_repo_version,
YAML_PATH: self._repo_info_text.path if self._repo_info_text else None, YAML_PATH: self._repo_info_text.pathname if self._repo_info_text else None,
YAML_TEXT: self._repo_info_text.real_text if self._repo_info_text else None YAML_TEXT: self._repo_info_text.real_text if self._repo_info_text else None
}, },
YAML_PYTEX: { YAML_PYTEX: {

View file

@ -5,11 +5,11 @@ from ..logger import logger
class GenericText: class GenericText:
def __init__(self, content: Optional[Union[List[str], Path]] = None): def __init__(self, content: Optional[Union[List[str], Path]] = None):
if isinstance(content, List): if isinstance(content, list):
self._content: Optional[List[str]] = content self._content: Optional[List[str]] = content
self._path = None self._path = None
self._initialized = True self._initialized = True
if isinstance(content, Path): elif isinstance(content, Path):
self._content: Optional[List[str]] = None self._content: Optional[List[str]] = None
self._path = content self._path = content
self._initialized = True self._initialized = True
@ -52,6 +52,10 @@ class GenericText:
def path(self) -> Optional[Path]: def path(self) -> Optional[Path]:
return self._path return self._path
@property
def pathname(self) -> Optional[str]:
return str(self._path) if self._path else None
def format(self, **kwargs) -> str: def format(self, **kwargs) -> str:
lines = [] lines = []
for line in self.text: for line in self.text: