kittv
/
prezgen
Archived
1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Dawid J. Kubis aeefa2c977 changed version info 3 years ago
Dawid J. Kubis 7f183e8423 v0.2.0 - working as (hopefully) intended
TODO actual error handling, cleaner code, less hard coded garbage
also hash output?
3 years ago

1
.gitignore vendored

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

@ -1,6 +1,6 @@
[package]
name = "prezgen"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -2,7 +2,7 @@ use structopt::StructOpt;
use toml::Value;
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;
#[derive(StructOpt, Debug)]
@ -25,7 +25,7 @@ struct Opt {
}
/// 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 {
let l = format!("{{{{ {} }}}}", x);
template = template.replace(&l, y)
@ -60,10 +60,10 @@ fn main() {
// read template
let input = read_to_string(
&[opt.output, PathBuf::from("front.html")]
&[opt.template, PathBuf::from("front.html")]
.iter()
.collect::<PathBuf>(),
);
).unwrap();
// create rules
@ -76,10 +76,15 @@ fn main() {
let global = collect_table(&value);
// iterate over pages
for i in page.as_array().unwrap() {
println!("{:?}", i);
for (index, value) in page.as_array().unwrap().iter().enumerate() {
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);