Skip to main content

web/pages/forms/
message.rs

1//! The one escaping path of the plain-text replies swapped into a result box.
2
3use askama::Template;
4use axum::response::{IntoResponse, Response};
5
6use crate::response::WebError;
7
8#[derive(Template)]
9#[template(source = "{{ text }}", ext = "html")]
10struct ResultMessage<'a> {
11    text: &'a str,
12}
13
14/// `text` as HTML-safe markup for an htmx swap into a result box.
15pub fn escaped(text: &str) -> Result<String, WebError> {
16    ResultMessage { text }
17        .render()
18        .map_err(|e| WebError::internal("Result message render failed", e))
19}
20
21/// The response of a plain-text `text` reply.
22pub fn reply(text: &str) -> Result<Response, WebError> {
23    Ok(escaped(text)?.into_response())
24}
25
26#[cfg(test)]
27#[path = "message_tests.rs"]
28mod tests;