Skip to content

Add the upon template engine #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"tmpls/sailfish",
"tmpls/tera",
"tmpls/tinytemplate",
"tmpls/upon",
]
resolver = "2"

Expand All @@ -26,7 +27,7 @@ license = "Apache-2.0"
default = ["compiled", "interpreted"]

compiled = ["askama", "horrorshow", "markup", "maud", "rinja", "rinja_git", "ructe", "sailfish"]
interpreted = ["handlebars", "minijinja", "tera", "tinytemplate"]
interpreted = ["handlebars", "minijinja", "tera", "tinytemplate", "upon"]

askama = ["dep:askama", "_contains_compiled"]
handlebars = ["dep:handlebars", "_contains_interpreted"]
Expand All @@ -40,6 +41,7 @@ ructe = ["dep:ructe", "_contains_compiled"]
sailfish = ["dep:sailfish", "_contains_compiled"]
tera = ["dep:tera", "_contains_interpreted"]
tinytemplate = ["dep:tinytemplate", "_contains_interpreted"]
upon = ["dep:upon", "_contains_interpreted"]

_contains_compiled = []
_contains_interpreted = []
Expand All @@ -59,6 +61,7 @@ ructe = { version = "*", optional = true, path = "tmpls/ructe", package = "tmpl-
sailfish = { version = "*", optional = true, path = "tmpls/sailfish", package = "tmpl-sailfish" }
tera = { version = "*", optional = true, path = "tmpls/tera", package = "tmpl-tera" }
tinytemplate = { version = "*", optional = true, path = "tmpls/tinytemplate", package = "tmpl-tinytemplate" }
upon = { version = "*", optional = true, path = "tmpls/upon", package = "tmpl-upon" }

ahash = { version = "0.8.11", features = ["no-rng"] }
criterion = { version = "0.5.1", features = ["html_reports"] }
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All of them are well maintained, mature and perform HTML escaping automatically.
| [sailfish] | [![][docs-img-sailfish]][docs-sailfish] | [![][img-repo]][repo-sailfish] | pre-compiled | [![][dl-sailfish]][sailfish] | [![][stars-sailfish]][repo-sailfish] | [![][contr-sailfish]][repo-sailfish] | [![][act-sailfish]][repo-sailfish] |
| [tera] | [![][docs-img-tera]][docs-tera] | [![][img-repo]][repo-tera] | interpreted | [![][dl-tera]][tera] | [![][stars-tera]][repo-tera] | [![][contr-tera]][repo-tera] | [![][act-tera]][repo-tera] |
| [tinytemplate] | [![][docs-img-tinytemplate]][docs-tinytemplate] | [![][img-repo]][repo-tinytemplate] | interpreted | [![][dl-tinytemplate]][tinytemplate] | [![][stars-tinytemplate]][repo-tinytemplate] | [![][contr-tinytemplate]][repo-tinytemplate] | [![][act-tinytemplate]][repo-tinytemplate] |
| [upon] | [![][docs-img-upon]][docs-upon] | [![][img-repo]][repo-upon] | interpreted | [![][dl-upon]][upon] | [![][stars-upon]][repo-upon] | [![][contr-upon]][repo-upon] | [![][act-upon]][repo-upon] |

Please see also [*Rust web framework comparison*].

Expand Down Expand Up @@ -62,6 +63,7 @@ Run `./generate-table.py` to generate the table you see above.
[sailfish]: <https://crates.io/crates/sailfish/>
[tera]: <https://crates.io/crates/tera/>
[tinytemplate]: <https://crates.io/crates/tinytemplate/>
[upon]: <https://crates.io/crates/upon/>

[docs-askama]: <https://docs.rs/askama/latest/askama>
[docs-handlebars]: <https://docs.rs/handlebars/latest/handlebars>
Expand All @@ -74,6 +76,7 @@ Run `./generate-table.py` to generate the table you see above.
[docs-sailfish]: <https://docs.rs/sailfish/latest/sailfish>
[docs-tera]: <https://docs.rs/tera/latest/tera>
[docs-tinytemplate]: <https://docs.rs/tinytemplate/latest/tinytemplate>
[docs-upon]: <https://docs.rs/upon/latest/upon>

[docs-img-askama]: <https://img.shields.io/docsrs/askama?label=&style=flat-square>
[docs-img-handlebars]: <https://img.shields.io/docsrs/handlebars?label=&style=flat-square>
Expand All @@ -86,6 +89,7 @@ Run `./generate-table.py` to generate the table you see above.
[docs-img-sailfish]: <https://img.shields.io/docsrs/sailfish?label=&style=flat-square>
[docs-img-tera]: <https://img.shields.io/docsrs/tera?label=&style=flat-square>
[docs-img-tinytemplate]: <https://img.shields.io/docsrs/tinytemplate?label=&style=flat-square>
[docs-img-upon]: <https://img.shields.io/docsrs/upon?label=&style=flat-square>

[dl-askama]: <https://img.shields.io/crates/dr/askama?label=&color=f8f8f8&style=flat-square>
[dl-handlebars]: <https://img.shields.io/crates/dr/handlebars?label=&color=f8f8f8&style=flat-square>
Expand All @@ -98,6 +102,7 @@ Run `./generate-table.py` to generate the table you see above.
[dl-sailfish]: <https://img.shields.io/crates/dr/sailfish?label=&color=f8f8f8&style=flat-square>
[dl-tera]: <https://img.shields.io/crates/dr/tera?label=&color=f8f8f8&style=flat-square>
[dl-tinytemplate]: <https://img.shields.io/crates/dr/tinytemplate?label=&color=f8f8f8&style=flat-square>
[dl-upon]: <https://img.shields.io/crates/dr/upon?label=&color=f8f8f8&style=flat-square>

[stars-askama]: <https://img.shields.io/github/stars/djc/askama?label=&color=f8f8f8&style=flat-square>
[stars-handlebars]: <https://img.shields.io/github/stars/sunng87/handlebars-rust?label=&color=f8f8f8&style=flat-square>
Expand All @@ -110,6 +115,7 @@ Run `./generate-table.py` to generate the table you see above.
[stars-sailfish]: <https://img.shields.io/github/stars/rust-sailfish/sailfish?label=&color=f8f8f8&style=flat-square>
[stars-tera]: <https://img.shields.io/github/stars/Keats/tera?label=&color=f8f8f8&style=flat-square>
[stars-tinytemplate]: <https://img.shields.io/github/stars/bheisler/TinyTemplate?label=&color=f8f8f8&style=flat-square>
[stars-upon]: <https://img.shields.io/github/stars/rossmacarthur/upon?label=&color=f8f8f8&style=flat-square>

[contr-askama]: <https://img.shields.io/github/contributors/djc/askama?label=&color=f8f8f8&style=flat-square>
[contr-handlebars]: <https://img.shields.io/github/contributors/sunng87/handlebars-rust?label=&color=f8f8f8&style=flat-square>
Expand All @@ -122,6 +128,7 @@ Run `./generate-table.py` to generate the table you see above.
[contr-sailfish]: <https://img.shields.io/github/contributors/rust-sailfish/sailfish?label=&color=f8f8f8&style=flat-square>
[contr-tera]: <https://img.shields.io/github/contributors/Keats/tera?label=&color=f8f8f8&style=flat-square>
[contr-tinytemplate]: <https://img.shields.io/github/contributors/bheisler/TinyTemplate?label=&color=f8f8f8&style=flat-square>
[contr-upon]: <https://img.shields.io/github/contributors/rossmacarthur/upon?label=&color=f8f8f8&style=flat-square>

[act-askama]: <https://img.shields.io/github/commit-activity/y/djc/askama?label=&color=f8f8f8&style=flat-square>
[act-handlebars]: <https://img.shields.io/github/commit-activity/y/sunng87/handlebars-rust?label=&color=f8f8f8&style=flat-square>
Expand All @@ -134,6 +141,7 @@ Run `./generate-table.py` to generate the table you see above.
[act-sailfish]: <https://img.shields.io/github/commit-activity/y/rust-sailfish/sailfish?label=&color=f8f8f8&style=flat-square>
[act-tera]: <https://img.shields.io/github/commit-activity/y/Keats/tera?label=&color=f8f8f8&style=flat-square>
[act-tinytemplate]: <https://img.shields.io/github/commit-activity/y/bheisler/TinyTemplate?label=&color=f8f8f8&style=flat-square>
[act-upon]: <https://img.shields.io/github/commit-activity/y/rossmacarthur/upon?label=&color=f8f8f8&style=flat-square>

[repo-askama]: <https://github.com/djc/askama>
[repo-handlebars]: <https://github.com/sunng87/handlebars-rust>
Expand All @@ -146,3 +154,4 @@ Run `./generate-table.py` to generate the table you see above.
[repo-sailfish]: <https://github.com/rust-sailfish/sailfish>
[repo-tera]: <https://github.com/Keats/tera>
[repo-tinytemplate]: <https://github.com/bheisler/TinyTemplate>
[repo-upon]: <https://github.com/rossmacarthur/upon>
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ macro_rules! for_each {
for_each!(tera, group, $input:$Input, $func);
#[cfg(feature = "tinytemplate")]
for_each!(tinytemplate, group, $input:$Input, $func);
#[cfg(feature = "upon")]
for_each!(upon, group, $input:$Input, $func);

group.finish();
};
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const TMPLS: &[(&str, fn(Case) -> Result<(), Error>)] = &[
("tera", tmpl::<tera::Benchmark>),
#[cfg(feature = "tinytemplate")]
("tinytemplate", tmpl::<tinytemplate::Benchmark>),
#[cfg(feature = "upon")]
("upon", tmpl::<upon::Benchmark>),
];

struct Tmpls(usize);
Expand Down
11 changes: 11 additions & 0 deletions tmpls/upon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "tmpl-upon"
version = "0.1.0"
edition = "2021"
publish = false
license = "Apache-2.0"

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

upon = { version = "0.8.1", default-features = false, features = [ "filters", "serde", "unicode" ] }
43 changes: 43 additions & 0 deletions tmpls/upon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use tmpls::{BigTable, Teams};
use upon::{Engine, Error};

#[derive(Debug)]
pub struct Benchmark {
engine: Engine<'static>,
}

impl Default for Benchmark {
fn default() -> Self {
let mut engine = Engine::new();
engine
.add_template("big-table", include_str!("../templates/big-table.html"))
.unwrap();
engine
.add_template("teams", include_str!("../templates/teams.html"))
.unwrap();
Self { engine }
}
}

impl tmpls::Benchmark for Benchmark {
type Output = Vec<u8>;
type Error = Error;

fn big_table(
&mut self,
output: &mut Self::Output,
input: &BigTable,
) -> Result<(), Self::Error> {
self.engine
.template("big-table")
.render(input)
.to_writer(output)
}

fn teams(&mut self, output: &mut Self::Output, input: &Teams) -> Result<(), Self::Error> {
self.engine
.template("teams")
.render(input)
.to_writer(output)
}
}
9 changes: 9 additions & 0 deletions tmpls/upon/templates/big-table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<table>
{%- for row in table -%}
<tr>
{%- for col in row -%}
<td>{{ col }}</td>
{%- endfor -%}
</tr>
{%- endfor -%}
</table>
15 changes: 15 additions & 0 deletions tmpls/upon/templates/teams.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>
<head>
<title>{{ year }}</title>
</head>
<body>
<h1>CSL {{ year }}</h1>
<ul>
{%- for team in teams %}
<li class="{% if loop.first %}champion{% endif %}">
<b>{{ team.name }}</b>: {{ team.score }}
</li>
{%- endfor %}
</ul>
</body>
</html>