blob: 33783c44680bca60c9e248236f270d8cb1c1ca69 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
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)
}
|