kittv
/
prezgen
Archived
1
0
Fork 0

Compare commits

..

No commits in common. 'aeefa2c97704faaae91cc4a6d836448f1d297d88' and 'c55cce3055d69113ce32032192ccb966f40d8304' have entirely different histories.

1
.gitignore vendored

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

@ -1,6 +1,6 @@
[package] [package]
name = "prezgen" name = "prezgen"
version = "0.2.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # 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 toml::Value;
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::fs::{copy, create_dir, read_to_string, write}; use std::fs::{copy, create_dir, read_to_string};
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: &[(String, String)]) -> String { fn replace(mut template: String, rules: &[(&str, &str)]) -> 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.template, PathBuf::from("front.html")] &[opt.output, PathBuf::from("front.html")]
.iter() .iter()
.collect::<PathBuf>(), .collect::<PathBuf>(),
).unwrap(); );
// create rules // create rules
@ -76,15 +76,10 @@ fn main() {
let global = collect_table(&value); let global = collect_table(&value);
// iterate over pages // iterate over pages
for (index, value) in page.as_array().unwrap().iter().enumerate() { for i in page.as_array().unwrap() {
let table = collect_table(&value); println!("{:?}", i);
let content = replace(input.clone(), table.as_slice()); // TODO create the files
// 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);