From 7a2db60d2259471c33e65b66cc4e3cb980ea6501 Mon Sep 17 00:00:00 2001 From: Ruben Moor Date: Mon, 6 Jul 2020 10:27:14 -0500 Subject: [PATCH] fixed template args --- src/preprocess/links.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index a6c30455..757887f1 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -252,17 +252,15 @@ fn parse_range_or_anchor(parts: Option<&str>) -> RangeOrAnchor { } } -fn parse_template_path(arg: &str) -> LinkType<'static> { - let mut param_pairs = arg.split_whitespace(); - let path: PathBuf = param_pairs.next().unwrap().into(); +fn parse_template_path(filepath: &str, params: Vec<&str>) -> LinkType<'static> { let mut dict = HashMap::new(); - param_pairs.for_each(|p| { + params.iter().for_each(|p| { let mut pair = p.splitn(2, ':'); - let key = pair.next().unwrap().to_string(); - let value = pair.next().unwrap().to_string(); + let key = pair.next().unwrap().to_owned(); + let value = pair.next().unwrap().to_owned(); dict.insert(key, value); }); - LinkType::Template(path, dict) + LinkType::Template(filepath.into(), dict) } fn parse_include_path(path: &str) -> LinkType<'static> { @@ -314,7 +312,7 @@ impl<'a> Link<'a> { Some(LinkType::Playground(pth.into(), props)) } ("rustdoc_include", Some(pth)) => Some(parse_rustdoc_include_path(pth)), - ("template", Some(pth)) => Some(parse_template_path(pth)), + ("template", Some(pth)) => Some(parse_template_path(pth, props)), _ => None, } } @@ -408,14 +406,20 @@ impl<'a> Link<'a> { fs::read_to_string(&target) .map(|s| { dict.iter().fold(s, |r, (key, value)| { - r.replace(format!("{{ {} }}", key).as_str(), value) + r.replace(format!("{{{{ {} }}}}", key).as_str(), value) }) }) .with_context(|| { format!( - "Could not read file for template {} ({})", + "Could not read file for template {} ({}), dict:{}", self.link_text, target.display(), + dict.iter() + .fold("".to_owned(), |s, (key, value)| s + format!( + " {} => {},", + key, value + ) + .as_str()) ) }) }