Skip to content

Commit

Permalink
Implement #444
Browse files Browse the repository at this point in the history
  • Loading branch information
ReagentX committed Jan 24, 2025
1 parent d87f8bd commit eddc1f2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
34 changes: 34 additions & 0 deletions imessage-exporter/src/exporters/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,17 @@ impl<'a> BalloonFormatter<&'a Message> for HTML<'a> {
out_s.push_str("\" </audio>");
}

// Add lyrics, if any
if let Some(lyrics) = &balloon.lyrics {
out_s.push_str("<div class=\"ldtext\">");
for line in lyrics {
out_s.push_str("<p>");
out_s.push_str(line);
out_s.push_str("</p>");
}
out_s.push_str("</div>");
}

// Header end
out_s.push_str("</div>");

Expand Down Expand Up @@ -2461,6 +2472,7 @@ mod balloon_format_tests {
artist: Some("artist"),
album: Some("album"),
track_name: Some("track_name"),
lyrics: None,
};

let expected = exporter.format_music(&balloon, &Config::fake_message());
Expand All @@ -2469,6 +2481,28 @@ mod balloon_format_tests {
assert_eq!(expected, actual);
}

#[test]
fn can_format_html_music_lyrics() {
// Create exporter
let options = Options::fake_options(crate::app::export_type::ExportType::Html);
let config = Config::fake_app(options);
let exporter = HTML::new(&config).unwrap();

let balloon = MusicMessage {
url: Some("url"),
preview: None,
artist: Some("artist"),
album: Some("album"),
track_name: Some("track_name"),
lyrics: Some(vec!["a", "b"]),
};

let expected = exporter.format_music(&balloon, &Config::fake_message());
let actual = "<div class=\"app_header\"><div class=\"name\">track_name</div><div class=\"ldtext\"><p>a</p><p>b</p></div></div><a href=\"url\"><div class=\"app_footer\"><div class=\"caption\">artist</div><div class=\"subcaption\">album</div></div></a>";

assert_eq!(expected, actual);
}

#[test]
fn can_format_html_collaboration() {
// Create exporter
Expand Down
31 changes: 31 additions & 0 deletions imessage-exporter/src/exporters/txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,14 @@ impl<'a> BalloonFormatter<&'a str> for TXT<'a> {
fn format_music(&self, balloon: &MusicMessage, indent: &str) -> String {
let mut out_s = String::new();

if let Some(lyrics) = &balloon.lyrics {
self.add_line(&mut out_s, "Lyrics:", indent);
for line in lyrics {
self.add_line(&mut out_s, line, indent);
}
self.add_line(&mut out_s, "\n", indent);
}

if let Some(track_name) = balloon.track_name {
self.add_line(&mut out_s, track_name, indent);
}
Expand Down Expand Up @@ -1869,6 +1877,7 @@ mod balloon_format_tests {
artist: Some("artist"),
album: Some("album"),
track_name: Some("track_name"),
lyrics: None,
};

let expected = exporter.format_music(&balloon, "");
Expand All @@ -1877,6 +1886,28 @@ mod balloon_format_tests {
assert_eq!(expected, actual);
}

#[test]
fn can_format_txt_music_lyrics() {
// Create exporter
let options = Options::fake_options(crate::app::export_type::ExportType::Txt);
let config = Config::fake_app(options);
let exporter = TXT::new(&config).unwrap();

let balloon = MusicMessage {
url: Some("url"),
preview: None,
artist: Some("artist"),
album: Some("album"),
track_name: Some("track_name"),
lyrics: Some(vec!["a", "b"]),
};

let expected = exporter.format_music(&balloon, "");
let actual = "Lyrics:\na\nb\n\n\ntrack_name\nalbum\nartist\nurl\n";

assert_eq!(expected, actual);
}

#[test]
fn can_format_txt_collaboration() {
// Create exporter
Expand Down

0 comments on commit eddc1f2

Please sign in to comment.