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
*.swp
test.toml
out/

@ -1,6 +1,6 @@
[package]
name = "prezgen"
version = "0.2.0"
version = "0.1.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, write};
use std::fs::{copy, create_dir, read_to_string};
use std::path::PathBuf;
#[derive(StructOpt, Debug)]
@ -25,7 +25,7 @@ struct Opt {
}
/// 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 {
let l = format!("{{{{ {} }}}}", x);
template = template.replace(&l, y)
@ -60,10 +60,10 @@ fn main() {
// read template
let input = read_to_string(
&[opt.template, PathBuf::from("front.html")]
&[opt.output, PathBuf::from("front.html")]
.iter()
.collect::<PathBuf>(),
).unwrap();
);
// create rules
@ -76,15 +76,10 @@ fn main() {
let global = collect_table(&value);
// iterate over pages
for (index, value) in page.as_array().unwrap().iter().enumerate() {
let table = collect_table(&value);
for i in page.as_array().unwrap() {
println!("{:?}", i);
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);
// TODO create the files
}
//println!("{:#?}", global);