ensuring that slides can be created by different things
This commit is contained in:
parent
887fc733e7
commit
8f065380aa
7 changed files with 270 additions and 50 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::{collections::HashMap, mem::replace, path::PathBuf};
|
||||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use sqlx::{query, Connection, SqliteConnection};
|
||||
use sqlx::query;
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::{
|
||||
|
@ -13,15 +13,14 @@ use crate::{
|
|||
pub struct Song {
|
||||
pub title: String,
|
||||
pub lyrics: Option<String>,
|
||||
pub author: String,
|
||||
pub ccli: String,
|
||||
pub audio: PathBuf,
|
||||
pub verse_order: Vec<String>,
|
||||
pub background: PathBuf,
|
||||
pub background_type: Background,
|
||||
pub text_alignment: TextAlignment,
|
||||
pub font: String,
|
||||
pub font_size: i32,
|
||||
pub author: Option<String>,
|
||||
pub ccli: Option<String>,
|
||||
pub audio: Option<PathBuf>,
|
||||
pub verse_order: Option<Vec<String>>,
|
||||
pub background: Option<Background>,
|
||||
pub text_alignment: Option<TextAlignment>,
|
||||
pub font: Option<String>,
|
||||
pub font_size: Option<i32>,
|
||||
}
|
||||
|
||||
const VERSE_KEYWORDS: [&'static str; 24] = [
|
||||
|
@ -39,7 +38,7 @@ impl Modeling for Model<Song> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn add_to_db(&mut self, item: Self::Item) -> Result<()> {
|
||||
fn add_to_db(&mut self, _item: Self::Item) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -91,21 +90,20 @@ impl Model<Song> {
|
|||
let _ = self.add_item(Song {
|
||||
title: song.title,
|
||||
lyrics: Some(song.lyrics),
|
||||
author: song.author,
|
||||
ccli: song.ccli,
|
||||
audio: song.audio.into(),
|
||||
verse_order: song.verse_order.split(" ").map(|s| s.to_string()).collect(),
|
||||
background: song.background.into(),
|
||||
background_type: song.background_type.into(),
|
||||
author: Some(song.author),
|
||||
ccli: Some(song.ccli),
|
||||
audio: Some(song.audio.into()),
|
||||
verse_order: Some(song.verse_order.split(" ").map(|s| s.to_string()).collect()),
|
||||
background: Some(song.background.try_into().unwrap_or_default()),
|
||||
text_alignment: {
|
||||
if song.horizontal_text_alignment == "center" && song.vertical_text_alignment == "center" {
|
||||
TextAlignment::MiddleCenter
|
||||
Some(TextAlignment::MiddleCenter)
|
||||
} else {
|
||||
TextAlignment::TopCenter
|
||||
Some(TextAlignment::TopCenter)
|
||||
}
|
||||
},
|
||||
font: song.font,
|
||||
font_size: song.font_size,
|
||||
font: Some(song.font),
|
||||
font_size: Some(song.font_size),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -120,6 +118,13 @@ impl Model<Song> {
|
|||
impl Song {
|
||||
pub fn get_lyrics(&self) -> Result<Vec<String>> {
|
||||
let mut lyric_list = Vec::new();
|
||||
if self.lyrics.is_none() {
|
||||
return Err(eyre!("There is no lyrics here"))
|
||||
} else if self.verse_order.is_none() {
|
||||
return Err(eyre!("There is no verse_order here"))
|
||||
} else if self.verse_order.clone().is_some_and(|v| v.is_empty()) {
|
||||
return Err(eyre!("There is no verse_order here"))
|
||||
}
|
||||
if let Some(raw_lyrics) = self.lyrics.clone() {
|
||||
let raw_lyrics = raw_lyrics.as_str();
|
||||
let verse_order = self.verse_order.clone();
|
||||
|
@ -143,7 +148,7 @@ impl Song {
|
|||
}
|
||||
lyric_map.insert(verse_title, lyric);
|
||||
|
||||
for verse in verse_order {
|
||||
for verse in verse_order.unwrap_or_default() {
|
||||
let mut verse_name = "";
|
||||
debug!(verse = verse);
|
||||
for word in VERSE_KEYWORDS.clone() {
|
||||
|
@ -188,6 +193,7 @@ impl Song {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
|
||||
#[test]
|
||||
pub fn test_song_lyrics() {
|
||||
|
@ -256,7 +262,7 @@ You saved my soul"
|
|||
"O1 V1 C1 C2 O2 V2 C3 C2 O2 B1 C2 C2 E1 O2"
|
||||
.to_string()
|
||||
.split(' ')
|
||||
.map(|s| s.to_string())
|
||||
.map(|s| Some(s.to_string()))
|
||||
.collect();
|
||||
let lyrics = song.get_lyrics();
|
||||
match lyrics {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue