|
|
@ -24,8 +24,23 @@ struct Opt {
|
|
|
|
template: PathBuf,
|
|
|
|
template: PathBuf,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn replace(input: String, rules: &[(&str, &str)]) -> String {
|
|
|
|
/// replaces {{ value }} with actual value
|
|
|
|
unimplemented!();
|
|
|
|
fn replace(mut template: String, rules: &[(&str, &str)]) -> String {
|
|
|
|
|
|
|
|
for (x, y) in rules {
|
|
|
|
|
|
|
|
let l = format!("{{{{ {} }}}}", x);
|
|
|
|
|
|
|
|
template = template.replace(&l, y)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// collects table into a vector of String pairs
|
|
|
|
|
|
|
|
fn collect_table(table: &Value) -> Vec<(String, String)> {
|
|
|
|
|
|
|
|
table.as_table()
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.keys()
|
|
|
|
|
|
|
|
.map(
|
|
|
|
|
|
|
|
|x| (x.clone(), String::from(table[x].as_str().unwrap()))
|
|
|
|
|
|
|
|
).collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
fn main() {
|
|
|
@ -34,12 +49,12 @@ fn main() {
|
|
|
|
//println!("{:?}", opt);
|
|
|
|
//println!("{:?}", opt);
|
|
|
|
|
|
|
|
|
|
|
|
// parse toml
|
|
|
|
// parse toml
|
|
|
|
let value = read_to_string(&opt.toml).unwrap().parse::<Value>().unwrap();
|
|
|
|
let mut value = read_to_string(&opt.toml).unwrap().parse::<Value>().unwrap();
|
|
|
|
println!("{:#?}", value);
|
|
|
|
//println!("{:#?}", value);
|
|
|
|
|
|
|
|
|
|
|
|
// create output directory
|
|
|
|
// create output directory
|
|
|
|
// if it doesn't exist
|
|
|
|
// if it doesn't exist
|
|
|
|
if (!opt.output.exists()) {
|
|
|
|
if !opt.output.exists() {
|
|
|
|
create_dir(&opt.output).unwrap();
|
|
|
|
create_dir(&opt.output).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -50,8 +65,22 @@ fn main() {
|
|
|
|
.collect::<PathBuf>(),
|
|
|
|
.collect::<PathBuf>(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create rules
|
|
|
|
// create rules
|
|
|
|
let page = value.get("page").unwrap().as_array().unwrap();
|
|
|
|
// hope to god the toml is correctly formatted
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// start with removing page rules
|
|
|
|
|
|
|
|
let page = value.as_table_mut().unwrap().remove("page").unwrap().clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// collect global rules into a vec
|
|
|
|
|
|
|
|
let global = collect_table(&value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// iterate over pages
|
|
|
|
|
|
|
|
for i in page.as_array().unwrap() {
|
|
|
|
|
|
|
|
println!("{:?}", i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO create the files
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
println!("{:#?}", page);
|
|
|
|
//println!("{:#?}", global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|