From 27b279b672028b2ce5f9b3531d01e8576505f3cb Mon Sep 17 00:00:00 2001 From: "Dawid J. Kubis" Date: Wed, 6 Oct 2021 23:21:12 +0200 Subject: [PATCH] now reading template, although hardcoded to "front.html", working on parsing the rules --- src/main.rs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 24cd7b6..686857a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,9 @@ use structopt::StructOpt; use toml::Value; +use std::collections::hash_map::DefaultHasher; +use std::fs::{copy, create_dir, read_to_string}; use std::path::PathBuf; -use std::fs::{read_to_string, copy}; #[derive(StructOpt, Debug)] /// structure representing command line arguments @@ -23,6 +24,9 @@ struct Opt { template: PathBuf, } +fn replace(input: String, rules: &[(&str, &str)]) -> String { + unimplemented!(); +} fn main() { // parse command line arguments @@ -30,10 +34,24 @@ fn main() { //println!("{:?}", opt); // parse toml - let value = read_to_string(opt.toml) - .unwrap() - .parse::() - .unwrap(); - println!("{:?}", value); - + let value = read_to_string(&opt.toml).unwrap().parse::().unwrap(); + println!("{:#?}", value); + + // create output directory + // if it doesn't exist + if (!opt.output.exists()) { + create_dir(&opt.output).unwrap(); + } + + // read template + let input = read_to_string( + &[opt.output, PathBuf::from("front.html")] + .iter() + .collect::(), + ); + + // create rules + let page = value.get("page").unwrap().as_array().unwrap(); + + println!("{:#?}", page); }