now we can parse an entire presentation to a list of slides

This commit is contained in:
Chris Cochrun 2024-12-06 11:15:41 -06:00
parent 6779b0c77c
commit 87a26642fa
5 changed files with 193 additions and 19 deletions

View file

@ -1,6 +1,7 @@
use crisp::types::{Symbol, Value};
use tracing::error;
use crate::Slide;
use crate::{core::songs::lisp_to_song, Slide};
pub fn parse_lisp(value: Value) -> Vec<Slide> {
match &value {
@ -10,7 +11,14 @@ pub fn parse_lisp(value: Value) -> Vec<Slide> {
vec![slide]
}
Value::Symbol(Symbol(s)) if s == "song" => {
vec![Slide::default()]
let song = lisp_to_song(vec.clone());
match Slide::song_slides(&song) {
Ok(s) => s,
Err(e) => {
error!("Couldn't load song: {e}");
vec![Slide::default()]
}
}
}
Value::Symbol(Symbol(s)) if s == "load" => {
vec![Slide::default()]
@ -23,7 +31,7 @@ pub fn parse_lisp(value: Value) -> Vec<Slide> {
#[cfg(test)]
mod test {
use std::fs::read_to_string;
use std::{fs::read_to_string, path::PathBuf};
use crate::{Background, SlideBuilder, TextAlignment};
@ -49,6 +57,31 @@ mod test {
}
}
#[test]
fn test_parsing_lisp_presentation() {
let lisp =
read_to_string("./test_presentation.lisp").expect("oops");
let lisp_value = crisp::reader::read(&lisp);
let test_vec =
vec![test_slide(), test_second_slide(), song_slide()];
match lisp_value {
Value::List(value) => {
let mut slide_vec = vec![];
for value in value {
let mut vec = parse_lisp(value);
slide_vec.append(&mut vec);
}
let first_lisp_slide = &slide_vec[0];
let second_lisp_slide = &slide_vec[1];
let third_lisp_slide = &slide_vec[2];
assert_eq!(first_lisp_slide, &test_vec[0]);
assert_eq!(second_lisp_slide, &test_vec[1]);
assert_eq!(third_lisp_slide, &test_vec[2]);
}
_ => panic!("this should be a lisp"),
}
}
fn test_slide() -> Slide {
SlideBuilder::new()
.text("This is frodo")
@ -81,4 +114,22 @@ mod test {
.build()
.unwrap()
}
fn song_slide() -> Slide {
SlideBuilder::new()
.text("Death Was Arrested\nNorth Point Worship")
.background(
Background::try_from("~/nc/tfc/openlp/CMG - Bright Mountains 01.jpg")
.unwrap(),
)
.font("Quicksand Bold")
.font_size(60)
.text_alignment(TextAlignment::MiddleCenter)
.audio(PathBuf::from("file:///home/chris/music/North Point InsideOut/Nothing Ordinary, Pt. 1 (Live)/05 Death Was Arrested (feat. Seth Condrey).mp3"))
.video_loop(true)
.video_start_time(0.0)
.video_end_time(0.0)
.build()
.unwrap()
}
}