From 00879a22d10d77f18c7b7f6562d930e0ec681a07 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Mon, 2 May 2022 02:31:39 +0100 Subject: [PATCH] [TEM #1] - Refactor method 'replace' -> 'replace_template' --- src/lib.rs | 11 ++++++++--- src/links.rs | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8978361..e6ced57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ impl Preprocessor for Template { .map(|dir| src_dir.join(dir)) .expect("All book items have a parent"); - let content = replace(&chapter.content, base, source, 0); + let content = replace_template(&chapter.content, base, source, 0); chapter.content = content; } } @@ -50,7 +50,7 @@ impl Preprocessor for Template { } } -fn replace(chapter_content: &str, base: P1, source: P2, depth: usize) -> String +fn replace_template(chapter_content: &str, base: P1, source: P2, depth: usize) -> String where P1: AsRef, P2: AsRef, @@ -68,7 +68,12 @@ where Ok(new_content) => { if depth < MAX_LINK_NESTED_DEPTH { if let Some(rel_path) = link.link_type.relative_path(path) { - replaced.push_str(&replace(&new_content, rel_path, source, depth + 1)); + replaced.push_str(&replace_template( + &new_content, + rel_path, + source, + depth + 1, + )); } else { replaced.push_str(&new_content); } diff --git a/src/links.rs b/src/links.rs index 347ed5b..cf8ea1a 100644 --- a/src/links.rs +++ b/src/links.rs @@ -220,7 +220,7 @@ mod link_tests { use std::path::PathBuf; use crate::links::{extract_template_links, Link, LinkType}; - use crate::replace; + use crate::replace_template; #[test] fn test_escaped_template_link() { @@ -234,7 +234,7 @@ mod link_tests { ```hbs {{#template template.md}} << an escaped link! ```"; - assert_eq!(replace(start, "", "", 0), end); + assert_eq!(replace_template(start, "", "", 0), end); } #[test]