1
//! The one escaping path of the plain-text replies swapped into a result box.
2

            
3
use askama::Template;
4
use axum::response::{IntoResponse, Response};
5

            
6
use crate::response::WebError;
7

            
8
#[derive(Template)]
9
#[template(source = "{{ text }}", ext = "html")]
10
struct ResultMessage<'a> {
11
    text: &'a str,
12
}
13

            
14
/// `text` as HTML-safe markup for an htmx swap into a result box.
15
142
pub fn escaped(text: &str) -> Result<String, WebError> {
16
142
    ResultMessage { text }
17
142
        .render()
18
        .map_err(|e| WebError::internal("Result message render failed", e))
19
142
}
20

            
21
/// The response of a plain-text `text` reply.
22
114
pub fn reply(text: &str) -> Result<Response, WebError> {
23
114
    Ok(escaped(text)?.into_response())
24
114
}
25

            
26
#[cfg(test)]
27
#[path = "message_tests.rs"]
28
mod tests;