Skip to content

Commit 1ecbf54

Browse files
committed
template logic
1 parent 606cd61 commit 1ecbf54

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/preprocess/links.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ enum LinkType<'a> {
139139
RustdocInclude(PathBuf, RangeOrAnchor),
140140
Template(PathBuf, HashMap<String, String>),
141141
Title(&'a str),
142+
Template(PathBuf, HashMap<String, String>),
142143
}
143144

144145
#[derive(PartialEq, Debug, Clone)]
@@ -211,6 +212,7 @@ impl<'a> LinkType<'a> {
211212
LinkType::RustdocInclude(p, _) => Some(return_relative_path(base, &p)),
212213
LinkType::Template(p, _) => Some(return_relative_path(base, &p)),
213214
LinkType::Title(_) => None,
215+
LinkType::Template(p, _) => Some(return_relative_path(base, &p)),
214216
}
215217
}
216218
}
@@ -426,6 +428,23 @@ impl<'a> Link<'a> {
426428
*chapter_title = title.to_owned();
427429
Ok(String::new())
428430
}
431+
432+
LinkType::Template(ref pat, ref dict) => {
433+
let target = base.join(pat);
434+
fs::read_to_string(&target)
435+
.map(|s| {
436+
dict.iter().fold(s, |r, (key, value)| {
437+
r.replace(format!("{{ {} }}", key).as_str(), value)
438+
})
439+
})
440+
.with_context(|| {
441+
format!(
442+
"Could not read file for template {} ({})",
443+
self.link_text,
444+
target.display(),
445+
)
446+
})
447+
}
429448
}
430449
}
431450
}

0 commit comments

Comments
 (0)