aboutsummaryrefslogtreecommitdiff
path: root/server/book-export/src/book_html.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/book-export/src/book_html.rs')
-rw-r--r--server/book-export/src/book_html.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/server/book-export/src/book_html.rs b/server/book-export/src/book_html.rs
new file mode 100644
index 00000000..08a12e88
--- /dev/null
+++ b/server/book-export/src/book_html.rs
@@ -0,0 +1,89 @@
+/*
+ Hurry Curry! - a game about cooking
+ Copyright (C) 2025 Hurry Curry! Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+
+use crate::diagram_svg::diagram_svg;
+use hurrycurry_locale::{
+ Locale,
+ message::{MessageDisplayExt, PLAIN},
+};
+use hurrycurry_protocol::{
+ Gamedata, Message,
+ book::{Book, BookPage, Diagram},
+};
+
+pub fn render_html_book(data: &Gamedata, book: &Book, locale: &Locale) -> String {
+ BookR { book, data, locale }.to_string()
+}
+
+markup::define! {
+ BookR<'a>(data: &'a Gamedata, book: &'a Book, locale: &'a Locale) {
+ @markup::doctype()
+ html {
+ head {
+ style { @include_str!("book_html.css").replace(" ", "").replace("\n", "") }
+ title { "Recipe Book - Hurry Curry!" }
+ }
+ body {
+ @for (index, page) in book.pages.iter().enumerate() {
+ @PageR { data, locale, page, index }
+ }
+ }
+ }
+ }
+
+ PageR<'a>(index: usize, data: &'a Gamedata, locale: &'a Locale, page: &'a BookPage) {
+ section.pagegroup[id=format!("page{index}")] {
+ @match page {
+ BookPage::Cover => {
+ div.page {}
+ div.page {}
+ }
+ BookPage::Recipe { title, description, diagram } => {
+ div.page {
+ h1 { @MessageR { data, locale, message: title } }
+ p { @MessageR { data, locale, message: description } }
+ }
+ div.page {
+ @DiagramR { data, diagram }
+ }
+ }
+ BookPage::Text { .. } => {
+ div.page {}
+ div.page {}
+ }
+ BookPage::Contents { title, table } => {
+ div.page {
+ h1 { @MessageR { data, locale, message: title } }
+ ol { @for (label, page) in table {
+ li { a[href=format!("#page{page}")] { @MessageR { data, locale, message: label } } }
+ }}
+ }
+ div.page {}
+ }
+ }
+ }
+ }
+
+ MessageR<'a>(data: &'a Gamedata, locale: &'a Locale, message: &'a Message) {
+ @message.display_message(*locale, *data, &PLAIN)
+ }
+
+ DiagramR<'a>(data: &'a Gamedata, diagram: &'a Diagram) {
+ @markup::raw(diagram_svg(data, diagram).unwrap())
+ }
+}