use anyhow::Result;use handlebars::Handlebars;use rust_embed::RustEmbed;use serde::Serialize;use std::sync::Arc; #[derive(RustEmbed)]#[folder = "src/templates"]#[include = "*.hbs"]struct Assets; pub struct Templates(Handlebars<'static>); impl Templates { pub fn new() -> Arc<Self> { let mut handlebars = Handlebars::new(); handlebars.register_embed_templates::<Assets>().unwrap(); // Disable HTML escaping so you don't . handlebars.register_escape_fn(|text| text.into()); Arc::new(Self(handlebars)) }} pub trait Template: Sized { const TEMPLATE_NAME: &'static str; fn render(&self, templates: &Templates) -> Result<String> where Self: Serialize + Sized, { Ok(templates.0.render(Self::TEMPLATE_NAME, self)?) }} #[derive(Serialize)]pub struct JudgeDiffTemplate { repository_diff: String, assertion: String,} impl Template for JudgeDiffTemplate { const TEMPLATE_NAME: &'static str = "judge_diff.hbs";}
use anyhow::Result;
use handlebars::Handlebars;
use rust_embed::RustEmbed;
use serde::Serialize;
use std::sync::Arc;
#[derive(RustEmbed)]
#[folder = "src/templates"]
#[include = "*.hbs"]
struct Assets;
pub struct Templates(Handlebars<'static>);
impl Templates {
pub fn new() -> Arc<Self> {
let mut handlebars = Handlebars::new();
handlebars.register_embed_templates::<Assets>().unwrap();
// Disable HTML escaping so you don't .
handlebars.register_escape_fn(|text| text.into());
Arc::new(Self(handlebars))
}
}
pub trait Template: Sized {
const TEMPLATE_NAME: &'static str;
fn render(&self, templates: &Templates) -> Result<String>
where
Self: Serialize + Sized,
{
Ok(templates.0.render(Self::TEMPLATE_NAME, self)?)
}
}
#[derive(Serialize)]
pub struct JudgeDiffTemplate {
repository_diff: String,
assertion: String,
}
impl Template for JudgeDiffTemplate {
const TEMPLATE_NAME: &'static str = "judge_diff.hbs";
}