Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
[TEM #1] - Refactor method 'replace' -> 'replace_template'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoudham committed May 2, 2022
1 parent 7088cc2 commit 00879a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -50,7 +50,7 @@ impl Preprocessor for Template {
}
}

fn replace<P1, P2>(chapter_content: &str, base: P1, source: P2, depth: usize) -> String
fn replace_template<P1, P2>(chapter_content: &str, base: P1, source: P2, depth: usize) -> String
where
P1: AsRef<Path>,
P2: AsRef<Path>,
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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]
Expand Down

0 comments on commit 00879a2

Please sign in to comment.