From d6536f8a8848b13aee0723cb98cc62aa4a79ac74 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 19 Nov 2024 15:25:35 -0600 Subject: [PATCH] some updates --- Cargo.lock | 2 +- src/core/slide.rs | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9268f92..1d37588 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1257,7 +1257,7 @@ dependencies = [ [[package]] name = "crisp" version = "0.1.0" -source = "git+https://git.tfcconnection.org/chris/crisp#04a470d771bd86646d27ef35811fc7d6a3c7bafb" +source = "git+https://git.tfcconnection.org/chris/crisp#b01eda5e0e3df469b45ff91424f7ad6f806cbca3" dependencies = [ "lazy_static", "miette", diff --git a/src/core/slide.rs b/src/core/slide.rs index 9e450ba..996ebe1 100644 --- a/src/core/slide.rs +++ b/src/core/slide.rs @@ -10,8 +10,6 @@ use std::{ use crate::core::lisp::Symbol; -use super::lisp::get_lists; - #[derive( Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, )] @@ -207,11 +205,31 @@ fn lisp_to_slide(lisp: Vec) -> Slide { slide.background(lisp_to_background(background)); } else { slide.background(Background::default()); + }; + match slide.build() { + Ok(slide) => slide, + Err(e) => { + miette!("Shoot! Slide didn't build: {e}"); + Slide::default() + } } } -fn lisp_to_background(lisp: &Value) { - todo!() +fn lisp_to_background(lisp: &Value) -> Background { + match lisp { + Value::List(list) => { + if let Some(source) = list.iter().position(|v| { + v == Value::Keyword(Keyword::from("source")) + }) { + let path = list[source + 1]; + let path = String::from(path); + Background::from(path) + } else { + Background::default() + } + } + _ => Background::default(), + } } #[derive( @@ -233,7 +251,7 @@ impl SlideBuilder { Self::default() } - pub(crate) fn background( + pub(crate) fn background_path( mut self, background: PathBuf, ) -> Result { @@ -242,6 +260,14 @@ impl SlideBuilder { Ok(self) } + pub(crate) fn background( + mut self, + background: Background, + ) -> Self { + self.background.insert(background); + self + } + pub(crate) fn text(mut self, text: impl Into) -> Self { let _ = self.text.insert(text.into()); self