summary refs log tree commit diff stats
path: root/src/new
diff options
context:
space:
mode:
Diffstat (limited to 'src/new')
-rw-r--r--src/new/chapter.rs2
-rw-r--r--src/new/figure.rs28
-rw-r--r--src/new/mod.rs4
-rw-r--r--src/new/replacement.rs9
4 files changed, 39 insertions, 4 deletions
diff --git a/src/new/chapter.rs b/src/new/chapter.rs
index 9fb5301..429816f 100644
--- a/src/new/chapter.rs
+++ b/src/new/chapter.rs
@@ -5,7 +5,7 @@ use log::error;
 
 use crate::{
     config_file::Config,
-    constants::{NEXT_CHAPTER, NEXT_CHAPTER_INCLUDE_ONLY},
+    constants::marker::{NEXT_CHAPTER, NEXT_CHAPTER_INCLUDE_ONLY},
     file_tree::{FileTree, GeneratedFile},
 };
 
diff --git a/src/new/figure.rs b/src/new/figure.rs
new file mode 100644
index 0000000..3099f94
--- /dev/null
+++ b/src/new/figure.rs
@@ -0,0 +1,28 @@
+use std::path::Path;
+
+use crate::{
+    config_file::Config,
+    file_tree::{FileTree, GeneratedFile},
+};
+
+use super::{replacement::untemplatize_figure, MangledName};
+
+pub fn generate_new_figure(
+    config: &Config,
+    name: String,
+    project_root: &Path,
+) -> anyhow::Result<FileTree> {
+    let mut file_tree = FileTree::new();
+
+    let new_figure_text = untemplatize_figure(&config.templates.figure, &name);
+
+    file_tree.add_file(GeneratedFile::new_clobber(
+        project_root
+            .join("figures")
+            .join(format!("{}.tex", MangledName::new(&name))),
+        new_figure_text,
+        false,
+    ));
+
+    Ok(file_tree)
+}
diff --git a/src/new/mod.rs b/src/new/mod.rs
index fed4ff3..888930e 100644
--- a/src/new/mod.rs
+++ b/src/new/mod.rs
@@ -3,9 +3,11 @@ use std::fmt::Display;
 use convert_case::{Case, Casing};
 use deunicode::deunicode;
 
-pub mod chapter;
 pub mod replacement;
+
+pub mod chapter;
 pub mod section;
+pub mod figure;
 
 #[derive(PartialEq, Eq, PartialOrd, Ord)]
 pub struct MangledName(String);
diff --git a/src/new/replacement.rs b/src/new/replacement.rs
index 6878e61..0e9f27f 100644
--- a/src/new/replacement.rs
+++ b/src/new/replacement.rs
@@ -4,7 +4,7 @@ use chrono::{Local, TimeDelta, TimeZone};
 use log::debug;
 
 use crate::constants::{
-    DATE, REPLACEMENT_CHAPTER, REPLACEMENT_CHAPTER_SECTION, REPLACMENT_SECTION_TITLE,
+    DATE, REPLACEMENT_CHAPTER, REPLACEMENT_CHAPTER_SECTION, REPLACEMENT_FIGURE, REPLACMENT_SECTION,
 };
 
 fn get_current_date() -> String {
@@ -36,7 +36,7 @@ fn get_current_date() -> String {
 pub fn untemplatize_section(input: &str, new_section_name: &str, new_chapter_name: &str) -> String {
     input
         .replace(REPLACEMENT_CHAPTER_SECTION, &new_chapter_name)
-        .replace(REPLACMENT_SECTION_TITLE, &new_section_name)
+        .replace(REPLACMENT_SECTION, &new_section_name)
         .replace(DATE, &get_current_date())
 }
 
@@ -45,3 +45,8 @@ pub fn untemplatize_chapter(input: &str, new_chapter_name: &str) -> String {
         .replace(REPLACEMENT_CHAPTER, &new_chapter_name)
         .replace(DATE, &get_current_date())
 }
+pub fn untemplatize_figure(input: &str, new_figure_name: &str) -> String {
+    input
+        .replace(REPLACEMENT_FIGURE, &new_figure_name)
+        .replace(DATE, &get_current_date())
+}