1pub mod config;
2pub mod generate_liturgy;
3use generate_liturgy::{LiturgyGenerator, LiturgicalSeason, search_bible, Readings};
4use wasm_bindgen::prelude::*;
5use std::collections::HashMap;
6use serde::{Deserialize, Serialize};
7use chrono::{NaiveDate};
8
9#[derive(Deserialize, Serialize, Debug, Clone)]
16struct LiturgyAndSeason {
17 liturgy: Vec<Readings>,
18 season: HashMap<String, LiturgicalSeason>,
19}
20
21#[wasm_bindgen]
22pub fn wasm_generate_liturgy(date: &str, bible: &str) -> String {
23 let year: i32 = date.split("-").next().unwrap().parse().unwrap();
31 let generator = match LiturgyGenerator::new(year) {
32 Ok(content) => content,
33 Err(e) => {println!("Liturgy Init error: {e}"); return "".to_string();},
34 };
35 let (liturgy, season) = match generator.generate() {
36 Ok(content) => content,
37 Err(e) => {println!("Generator error: {e}"); return "".to_string();}
38 };
39
40 let mut search_liturgy = liturgy[date].clone();
41 search_bible(bible, &mut search_liturgy);
42
43 let liturgy_and_season = LiturgyAndSeason {
44 liturgy: search_liturgy,
45 season: season,
46 };
47
48 let serialized_liturgy = match serde_json::to_string_pretty(&liturgy_and_season) {
49 Ok(liturgy) => liturgy,
50 Err(e) => return "".to_string(),
51 };
52 println!("{}", serialized_liturgy);
53 return serialized_liturgy;
54}
55
56#[cfg(test)]
57mod wasm_tests {
58 use super::*;
59
60 #[test]
61 fn test_generate_liturgy() {
62 }
65
66}