index : livejrnl-rs.git

ascending towards madness

mod data {
	pub mod formats;
}
mod util {
	pub mod templating;
	pub mod journal;
}

const APP_NAME: &str = "livejrnl-rs";
const ERR_JOURNAL_NOT_FOUND: &str = "ERROR: No journal data specified.\n\nUsage:\n\tjrnl --format json | livejrnl-rs";

fn main() {
	let mut jrnl_json: String = String::new();
	if let Some(pipe) = read_pipe::read_pipe() {
		jrnl_json.push_str(&pipe);
	}
	else {
		println!("{}", ERR_JOURNAL_NOT_FOUND);
		return;
	}

	let journal: util::journal::Journal = util::journal::parse_journal_json(&jrnl_json);
	println!("{:#?}", journal);

	let config_data = load_config();
	match config_data {
		Ok(config_data) => {
			println!("{:#?}", config_data);

			let template_files = util::templating::get_templates(config_data.template.clone());
			println!("{:?}", template_files);

			let html = util::templating::render_html(config_data, journal, &template_files);
			println!("{}", html);
		},
		Err(error) => println!("{:#?}", error)
	};
}

fn load_config() -> Result<data::formats::RenderConfig, confy::ConfyError> {
    let cfg: data::formats::RenderConfig = confy::load(APP_NAME, "config")?;
    Ok(cfg)
}