Introduce handlebars to be able to do templating
This commit is contained in:
@@ -6,18 +6,30 @@
|
||||
// included at compile time and then run it to generate a new version of
|
||||
// README.md.
|
||||
|
||||
extern crate handlebars;
|
||||
#[macro_use]
|
||||
extern crate serde_json;
|
||||
|
||||
use handlebars::Handlebars;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let template = include_str!("../../README-template.md");
|
||||
let template = include_str!("../../README-template.hbs");
|
||||
let autogenerated_notice = "This file was autogenerated by the script in src/bin/generate_readme.rs.
|
||||
Please edit either the script or the template in README-template.md in
|
||||
order to make changes here rather than committing the changes directly.";
|
||||
|
||||
let mut generated_readme = File::create("README.md").unwrap();
|
||||
write!(generated_readme, "\
|
||||
<!-- This file was autogenerated by the script in src/bin/generate_readme.rs.
|
||||
Please edit either the script or the template in README-template.md in
|
||||
order to make changes here rather than committing the changes directly. -->
|
||||
|
||||
").unwrap();
|
||||
write!(generated_readme, "{}", template).unwrap();
|
||||
let hbs = Handlebars::new();
|
||||
write!(
|
||||
generated_readme,
|
||||
"{}",
|
||||
hbs.render_template(
|
||||
template,
|
||||
&json!({ "autogenerated_notice": autogenerated_notice }),
|
||||
).unwrap()
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user