summary refs log tree commit diff stats
path: root/src/new/mod.rs
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-06-18 16:32:47 +0200
committerSoispha <soispha@vhack.eu>2023-06-18 16:32:47 +0200
commit369bf07cbb36d8e72025014bfd4ddc52d9049fde (patch)
tree545b32762ec8af521484f6c520dc568edaf8a2f7 /src/new/mod.rs
downloadlpm-369bf07cbb36d8e72025014bfd4ddc52d9049fde.tar.gz
lpm-369bf07cbb36d8e72025014bfd4ddc52d9049fde.zip
Chore: Initial commit
Diffstat (limited to '')
-rw-r--r--src/new/mod.rs99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/new/mod.rs b/src/new/mod.rs
new file mode 100644
index 0000000..efc55cd
--- /dev/null
+++ b/src/new/mod.rs
@@ -0,0 +1,99 @@
+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)
+}