diff --git a/Cargo.toml b/Cargo.toml index 864f93d..00b9dae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ "tmpls/sailfish", "tmpls/tera", "tmpls/tinytemplate", + "tmpls/upon", ] resolver = "2" @@ -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"] @@ -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 = [] @@ -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"] } diff --git a/README.md b/README.md index f079ec4..6be5257 100644 --- a/README.md +++ b/README.md @@ -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*]. @@ -62,6 +63,7 @@ Run `./generate-table.py` to generate the table you see above. [sailfish]: [tera]: [tinytemplate]: +[upon]: [docs-askama]: [docs-handlebars]: @@ -74,6 +76,7 @@ Run `./generate-table.py` to generate the table you see above. [docs-sailfish]: [docs-tera]: [docs-tinytemplate]: +[docs-upon]: [docs-img-askama]: [docs-img-handlebars]: @@ -86,6 +89,7 @@ Run `./generate-table.py` to generate the table you see above. [docs-img-sailfish]: [docs-img-tera]: [docs-img-tinytemplate]: +[docs-img-upon]: [dl-askama]: [dl-handlebars]: @@ -98,6 +102,7 @@ Run `./generate-table.py` to generate the table you see above. [dl-sailfish]: [dl-tera]: [dl-tinytemplate]: +[dl-upon]: [stars-askama]: [stars-handlebars]: @@ -110,6 +115,7 @@ Run `./generate-table.py` to generate the table you see above. [stars-sailfish]: [stars-tera]: [stars-tinytemplate]: +[stars-upon]: [contr-askama]: [contr-handlebars]: @@ -122,6 +128,7 @@ Run `./generate-table.py` to generate the table you see above. [contr-sailfish]: [contr-tera]: [contr-tinytemplate]: +[contr-upon]: [act-askama]: [act-handlebars]: @@ -134,6 +141,7 @@ Run `./generate-table.py` to generate the table you see above. [act-sailfish]: [act-tera]: [act-tinytemplate]: +[act-upon]: [repo-askama]: [repo-handlebars]: @@ -146,3 +154,4 @@ Run `./generate-table.py` to generate the table you see above. [repo-sailfish]: [repo-tera]: [repo-tinytemplate]: +[repo-upon]: diff --git a/src/lib.rs b/src/lib.rs index 9e5d80f..3a82d7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(); }; diff --git a/src/main.rs b/src/main.rs index 18a6013..a643535 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,6 +94,8 @@ const TMPLS: &[(&str, fn(Case) -> Result<(), Error>)] = &[ ("tera", tmpl::), #[cfg(feature = "tinytemplate")] ("tinytemplate", tmpl::), + #[cfg(feature = "upon")] + ("upon", tmpl::), ]; struct Tmpls(usize); diff --git a/tmpls/upon/Cargo.toml b/tmpls/upon/Cargo.toml new file mode 100644 index 0000000..6b0d40a --- /dev/null +++ b/tmpls/upon/Cargo.toml @@ -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" ] } diff --git a/tmpls/upon/src/lib.rs b/tmpls/upon/src/lib.rs new file mode 100644 index 0000000..13e5472 --- /dev/null +++ b/tmpls/upon/src/lib.rs @@ -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; + 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) + } +} diff --git a/tmpls/upon/templates/big-table.html b/tmpls/upon/templates/big-table.html new file mode 100644 index 0000000..60f566e --- /dev/null +++ b/tmpls/upon/templates/big-table.html @@ -0,0 +1,9 @@ + + {%- for row in table -%} + + {%- for col in row -%} + + {%- endfor -%} + + {%- endfor -%} +
{{ col }}
diff --git a/tmpls/upon/templates/teams.html b/tmpls/upon/templates/teams.html new file mode 100644 index 0000000..ec29841 --- /dev/null +++ b/tmpls/upon/templates/teams.html @@ -0,0 +1,15 @@ + + + {{ year }} + + +

CSL {{ year }}

+
    + {%- for team in teams %} +
  • + {{ team.name }}: {{ team.score }} +
  • + {%- endfor %} +
+ +