diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:35 +0000 |
commit | 7e5d7eea9c580ef4b41a765bde624af431942b96 (patch) | |
tree | 2c0d9ca12878fc4525650aa4e54d77a81a07cc09 /vendor/handlebars-3.5.5/examples/script.rs | |
parent | Adding debian version 1.70.0+dfsg1-9. (diff) | |
download | rustc-7e5d7eea9c580ef4b41a765bde624af431942b96.tar.xz rustc-7e5d7eea9c580ef4b41a765bde624af431942b96.zip |
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/handlebars-3.5.5/examples/script.rs')
-rw-r--r-- | vendor/handlebars-3.5.5/examples/script.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/handlebars-3.5.5/examples/script.rs b/vendor/handlebars-3.5.5/examples/script.rs new file mode 100644 index 000000000..bedd426cd --- /dev/null +++ b/vendor/handlebars-3.5.5/examples/script.rs @@ -0,0 +1,39 @@ +#![allow(unused_imports)] + +use handlebars::Handlebars; +use std::error::Error; +#[macro_use] +extern crate serde_json; + +#[cfg(feature = "script_helper")] +fn main() -> Result<(), Box<dyn Error>> { + let mut handlebars = Handlebars::new(); + + handlebars.register_template_file("tpl", "./examples/script/template.hbs")?; + handlebars.register_script_helper_file("score", "./examples/script/goals.rhai")?; + + let data = json! {[ + [{ + "name": "Dortmund", + "goals": ["Haaland", "Guerreiro", "Hazard", "Guerreiro"] + }, { + "name": "Schalke", + "goals": [] + }], + [{ + "name": "RB Leipzig", + "goals": ["Poulsen"] + }, { + "name": "SC Feriburg", + "goals": ["Gulde"] + }] + ]}; + println!("{}", handlebars.render("tpl", &data)?); + Ok(()) +} + +#[cfg(not(feature = "script_helper"))] +fn main() -> Result<(), Box<dyn Error>> { + println!("Please enable feature flag script_helper for this example"); + Ok(()) +} |