kittv
/
prezgen
Archived
1
0
Fork 0

v0.2.0 - working as (hopefully) intended

TODO actual error handling, cleaner code, less hard coded garbage
also hash output?
master
Dawid J. Kubis 3 years ago
parent c55cce3055
commit 7f183e8423

1
.gitignore vendored

@ -1,3 +1,4 @@
/target /target
*.swp *.swp
test.toml test.toml
out/

@ -2,7 +2,7 @@ use structopt::StructOpt;
use toml::Value; use toml::Value;
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::fs::{copy, create_dir, read_to_string}; use std::fs::{copy, create_dir, read_to_string, write};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
@ -25,7 +25,7 @@ struct Opt {
} }
/// replaces {{ value }} with actual value /// replaces {{ value }} with actual value
fn replace(mut template: String, rules: &[(&str, &str)]) -> String { fn replace(mut template: String, rules: &[(String, String)]) -> String {
for (x, y) in rules { for (x, y) in rules {
let l = format!("{{{{ {} }}}}", x); let l = format!("{{{{ {} }}}}", x);
template = template.replace(&l, y) template = template.replace(&l, y)
@ -60,10 +60,10 @@ fn main() {
// read template // read template
let input = read_to_string( let input = read_to_string(
&[opt.output, PathBuf::from("front.html")] &[opt.template, PathBuf::from("front.html")]
.iter() .iter()
.collect::<PathBuf>(), .collect::<PathBuf>(),
); ).unwrap();
// create rules // create rules
@ -76,10 +76,15 @@ fn main() {
let global = collect_table(&value); let global = collect_table(&value);
// iterate over pages // iterate over pages
for i in page.as_array().unwrap() { for (index, value) in page.as_array().unwrap().iter().enumerate() {
println!("{:?}", i); let table = collect_table(&value);
// TODO create the files let content = replace(input.clone(), table.as_slice());
// create the files
let target = format!("front-{}.html", index);
println!("writing {}", target);
write(&[&opt.output, &PathBuf::from(target)].iter().collect::<PathBuf>(), content);
} }
//println!("{:#?}", global); //println!("{:#?}", global);