rework format method to support multiple output files

This commit is contained in:
Maximilian Keßler 2022-02-09 18:02:41 +01:00
parent 6798962880
commit 3e6f2f99c3
2 changed files with 14 additions and 16 deletions

View file

@ -14,13 +14,6 @@ class SimpleTeXFormatter(TexFormatter):
} }
return self.name + switcher[self.config.tex_type] return self.name + switcher[self.config.tex_type]
def open_output_stream(self, build_dir: Path):
out_file = build_dir / self.output_file
if out_file.exists():
raise NotImplementedError
else:
self._output_file = out_file.open('w')
def close_output_stream(self): def close_output_stream(self):
self._output_file.close() self._output_file.close()

View file

@ -62,12 +62,16 @@ class TexFormatter(PyTeXFormatter, ABC):
self._macros: List[Macro] = [] self._macros: List[Macro] = []
self._line_stream: Optional[LineStream] = None self._line_stream: Optional[LineStream] = None
@abstractmethod def open_output_stream(self, build_dir: Path, filename: str) -> None:
def open_output_stream(self, build_dir: Path) -> None:
""" """
:param build_dir: Where to open output stream :param build_dir: Where to open output stream
:param filename: Name of file
""" """
out_file = build_dir / filename
if out_file.exists():
raise NotImplementedError
else:
self._output_file = out_file.open('w')
@abstractmethod @abstractmethod
def close_output_stream(self) -> None: def close_output_stream(self) -> None:
@ -151,10 +155,11 @@ class TexFormatter(PyTeXFormatter, ABC):
)) ))
def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]: def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]:
self.open_output_stream(build_dir) for filename in self.output_files:
self.format_pre_header() self.open_output_stream(build_dir, filename)
self.format_header() self.format_pre_header()
self.format_post_header() self.format_header()
self.format_document() self.format_post_header()
self.close_output_stream() self.format_document()
self.close_output_stream()
return self.future_config return self.future_config