diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-03-31 21:57:01 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-03-31 21:57:01 +0200 |
commit | 2e5e4b5736c446198e36760e254b7c17dd987166 (patch) | |
tree | b74915864a2c80dbc0a0ebe26a52140a934f45c5 /src/new/mod.rs | |
parent | docs(example): Add an example directory (diff) | |
download | lpm-2e5e4b5736c446198e36760e254b7c17dd987166.tar.gz lpm-2e5e4b5736c446198e36760e254b7c17dd987166.zip |
refactor(treewide): Improve code quality by working with a FileTree
The FileTree has been taken from the implementation written by my for the Trinitrix project. It alleviates the problem, where functions had to do many things themselves.
Diffstat (limited to 'src/new/mod.rs')
-rw-r--r-- | src/new/mod.rs | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/src/new/mod.rs b/src/new/mod.rs index 33783c4..a85187c 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -1,97 +1,2 @@ pub mod chapter; -pub mod project; pub mod section; - -use std::{ - env, - ffi::OsString, - fs::read_dir, - io::{self, ErrorKind}, - path::PathBuf, -}; - -const SECTION: &'static str = r#"%! TEX root = ../../../main.tex -% LTeX: language=de-DE - -\lesson{REPLACMENT_SECTION_TITLE}{DATE}{} -Dies ist etwas Text -"#; - -const CHAPTER: &'static str = r#"%! TEX root = ../main.tex -% LTeX: language=de-DE - -\chapter{REPLACEMENT_CHAPTER} -"#; - -const TITLE_FILE: &'static str = r#"% LTeX: language=de-DE - -\maketitle -\tableofcontents -\vspace*{\fill} -\makeatletter -Copyright \textcopyright{} \@authors{} \@years{}\\ -\ \\ -Dieses Werk ist lizenziert unter den Bedingungen der CC BY-SA 4.0. -Der Lizenztext ist online unter \url{http://creativecommons.org/licenses/by-sa/4.0/legalcode} abrufbar. -\makeatother -\clearpage -"#; - -const MAIN_FILE: &'static str = r#"%\documentclass[a4paper, 12pt, nosolutions]{report} -\documentclass[a4paper, 12pt]{report} -% LTeX: language=de-DE -\input{headers/preamble.tex} -\input{headers/preamble_local.tex} - - -\title{\textbf{Titel}} -\author{Name\thanks{Beispiel}} -\authors{Name} -\years{2022 - 2023} -\date{\DTMDate{2002-12-4}} - -\includeonly{content/REPLACEMENT_CHAPTER/chapter_01} - -\begin{document} - \input{content/static/title} - - \include{content/REPLACEMENT_CHAPTER/chapter_01} - % NEXT_CHAPTER - - \printbibliography\relax -\end{document} -"#; - -pub fn get_project_root() -> io::Result<PathBuf> { - let path = env::current_dir()?; - let mut path_ancestors = path.as_path().ancestors(); - - while let Some(path_segment) = path_ancestors.next() { - if read_dir(path_segment)?.into_iter().any(|path_segment| { - path_segment - .expect("The read_dir shouldn't error out here") - .file_name() - == OsString::from("lpm.toml") - }) { - return Ok(PathBuf::from(path_segment)); - } - } - Err(io::Error::new( - ErrorKind::NotFound, - "Ran out of places to find lpm.toml", - )) -} - -pub fn get_all_chapters() -> io::Result<Vec<String>> { - let path = get_project_root()?; - let output = read_dir(path.join("content"))? - .map(|path| { - path.expect("The values sholud be fine") - .file_name() - .to_str() - .expect("all names should be valid utf-8") - .to_owned() - }) - .collect(); - Ok(output) -} |