From 7e5d7eea9c580ef4b41a765bde624af431942b96 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:41:35 +0200 Subject: Merging upstream version 1.70.0+dfsg2. Signed-off-by: Daniel Baumann --- vendor/handlebars-3.5.5/examples/script.rs | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 vendor/handlebars-3.5.5/examples/script.rs (limited to 'vendor/handlebars-3.5.5/examples/script.rs') 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> { + 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> { + println!("Please enable feature flag script_helper for this example"); + Ok(()) +} -- cgit v1.2.3