feat(template-askama): add Askama template adapter for diary entries

This commit is contained in:
2026-05-04 02:04:52 +02:00
parent c4b39c9410
commit b6a7cf9417
7 changed files with 227 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
// crates/adapters/template-askama/src/lib.rs
use askama::Template;
use domain::models::{DiaryEntry, collections::Paginated};
use presentation::ports::HtmlRenderer; // Assuming you exposed the port
// The internal Askama template
#[derive(Template)]
#[template(path = "diary.html")]
struct DiaryTemplate<'a> {
entries: &'a [DiaryEntry],
current_offset: u32,
limit: u32,
has_more: bool,
}
// The public adapter struct
pub struct AskamaHtmlRenderer;
impl AskamaHtmlRenderer {
pub fn new() -> Self {
Self {}
}
}
// Implementing the presentation port
impl HtmlRenderer for AskamaHtmlRenderer {
fn render_diary_page(&self, data: &Paginated<DiaryEntry>) -> Result<String, String> {
let has_more = (data.offset + data.limit) < data.total_count as u32;
let template = DiaryTemplate {
entries: &data.items,
current_offset: data.offset,
limit: data.limit,
has_more,
};
template.render().map_err(|e| e.to_string())
}
}