Skip to content

Commit

Permalink
+= maud
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Aug 14, 2024
1 parent 8aaa94f commit ed29439
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ publish = false
license = "Apache-2.0"

[features]
default = ["askama", "handlebars", "horrorshow", "markup", "minijinja", "rinja", "ructe", "sailfish", "tera", "tinytemplate"]
default = ["askama", "handlebars", "horrorshow", "markup", "maud", "minijinja", "rinja", "ructe", "sailfish", "tera", "tinytemplate"]
askama = ["dep:askama"]
handlebars = ["dep:handlebars"]
horrorshow = ["dep:horrorshow"]
markup = ["dep:markup"]
maud = ["dep:maud"]
minijinja = ["dep:minijinja"]
rinja = ["dep:rinja"]
ructe = ["dep:ructe"]
Expand All @@ -41,6 +42,7 @@ askama = { version = "*", optional = true, path = "tmpls/askama", package = "tmp
handlebars = { version = "*", optional = true, path = "tmpls/handlebars", package = "tmpl-handlebars" }
horrorshow = { version = "*", optional = true, path = "tmpls/horrorshow", package = "tmpl-horrorshow" }
markup = { version = "*", optional = true, path = "tmpls/markup", package = "tmpl-markup" }
maud = { version = "*", optional = true, path = "tmpls/maud", package = "tmpl-maud" }
minijinja = { version = "*", optional = true, path = "tmpls/minijinja", package = "tmpl-minijinja" }
rinja = { version = "*", optional = true, path = "tmpls/rinja", package = "tmpl-rinja" }
ructe = { version = "*", optional = true, path = "tmpls/ructe", package = "tmpl-ructe" }
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ macro_rules! for_each {
for_each!(horrorshow, group, $input:$Input, $func);
#[cfg(feature = "markup")]
for_each!(markup, group, $input:$Input, $func);
#[cfg(feature = "maud")]
for_each!(maud, group, $input:$Input, $func);
#[cfg(feature = "minijinja")]
for_each!(minijinja, group, $input:$Input, $func);
#[cfg(feature = "rinja")]
Expand Down
12 changes: 12 additions & 0 deletions tmpls/maud/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "tmpl-maud"
version = "0.1.0"
edition = "2021"
publish = false
license = "Apache-2.0"

[dependencies]
tmpls = { version = "*", path = ".." }

maud = "0.26.0"

54 changes: 54 additions & 0 deletions tmpls/maud/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::convert::Infallible;

use maud::html;
use tmpls::{BigTable, Teams};

#[derive(Debug, Default)]
pub struct Benchmark;

impl tmpls::Benchmark for Benchmark {
type Output = String;
type Error = Infallible;

fn big_table(
&mut self,
output: &mut Self::Output,
input: &BigTable,
) -> Result<(), Self::Error> {
*output = html! {
table {
@for row in &input.table {
tr {
@for col in row {
td { (col) }
}
}
}
}
}
.0;
Ok(())
}

fn teams(&mut self, output: &mut Self::Output, input: &Teams) -> Result<(), Self::Error> {
*output = html! {
html {
head {
title { (input.year) }
}
body {
h1 { "CLS " (input.year) }
ul {
@for (idx, team) in input.teams.iter().enumerate() {
li.champion[idx == 0] {
b { (team.name) } ": " (team.score)
}
}
}
}
}
}
.0;
Ok(())
}
}

0 comments on commit ed29439

Please sign in to comment.