fixed template args
This commit is contained in:
parent
0557afcb71
commit
7a2db60d22
|
@ -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())
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue