kittv
/
prezgen
Archived
1
0
Fork 0

Compare commits

..

No commits in common. '305e7ea0c5ed7f15e853dc7a64a5faf1df39a831' and '643d734679d2a5fbae87721895598e13a55d2556' have entirely different histories.

7
Cargo.lock generated

@ -43,12 +43,6 @@ dependencies = [
"vec_map", "vec_map",
] ]
[[package]]
name = "deunicode"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2c9736e15e7df1638a7f6eee92a6511615c738246a052af5ba86f039b65aede"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.3.3" version = "0.3.3"
@ -83,7 +77,6 @@ checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
name = "prezgen" name = "prezgen"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"deunicode",
"structopt", "structopt",
"toml", "toml",
] ]

@ -8,4 +8,3 @@ edition = "2021"
[dependencies] [dependencies]
structopt = "0.3.23" structopt = "0.3.23"
toml = "0.5.8" toml = "0.5.8"
deunicode = "1.3.1"

@ -1,4 +1,3 @@
use deunicode::deunicode;
use structopt::StructOpt; use structopt::StructOpt;
use toml::Value; use toml::Value;
@ -36,12 +35,12 @@ fn replace(mut template: String, rules: &[(String, String)]) -> String {
/// collects table into a vector of String pairs /// collects table into a vector of String pairs
fn collect_table(table: &Value) -> Vec<(String, String)> { fn collect_table(table: &Value) -> Vec<(String, String)> {
table table.as_table()
.as_table()
.unwrap() .unwrap()
.keys() .keys()
.map(|x| (x.clone(), String::from(table[x].as_str().unwrap()))) .map(
.collect() |x| (x.clone(), String::from(table[x].as_str().unwrap()))
).collect()
} }
fn main() { fn main() {
@ -64,19 +63,14 @@ fn main() {
&[opt.template, PathBuf::from("front.html")] &[opt.template, PathBuf::from("front.html")]
.iter() .iter()
.collect::<PathBuf>(), .collect::<PathBuf>(),
) ).unwrap();
.unwrap();
// create rules // create rules
// hope to god the toml is correctly formatted // hope to god the toml is correctly formatted
// start with removing page rules // start with removing page rules
let page = value let page = value.as_table_mut().unwrap().remove("page").unwrap().clone();
.as_table_mut()
.unwrap()
.remove("page")
.unwrap()
.clone();
// collect global rules into a vec // collect global rules into a vec
let global = collect_table(&value); let global = collect_table(&value);
@ -84,40 +78,18 @@ fn main() {
// iterate over pages // iterate over pages
for (index, value) in page.as_array().unwrap().iter().enumerate() { for (index, value) in page.as_array().unwrap().iter().enumerate() {
// add global variables to table // add global variables to table
// FIXME
let mut table = collect_table(&value); let mut table = collect_table(&value);
table.extend(global.clone()); table.extend(global.clone());
// TODO make this less of a pain
let content = replace(input.clone(), table.as_slice()); let content = replace(input.clone(), table.as_slice());
// create the files // create the files
let (code, day, time_start) = ( let target = format!("front-{}.html", index);
value["code"].as_str().unwrap(),
value["day"].as_str().unwrap(),
value["time_start"].as_str().unwrap(),
);
// tweaks
// day
let mut day = String::from(day);
day = deunicode(&day).to_uppercase();
// time_start
let mut time_start = String::from(time_start);
time_start = time_start.replace(":", "");
// code
let code = String::from(code).replace(" ", "-");
let target = format!("PREZ_{}_{}_{}.html", code, &day[0..2], time_start);
println!("writing {}", target); println!("writing {}", target);
write( write(&[&opt.output, &PathBuf::from(target)].iter().collect::<PathBuf>(), content)
&[&opt.output, &PathBuf::from(target)] .unwrap();
.iter()
.collect::<PathBuf>(),
content,
)
.unwrap();
} }
//println!("{:#?}", global); //println!("{:#?}", global);
} }