summaryrefslogtreecommitdiffstats
path: root/vendor/handlebars/examples/script.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/handlebars/examples/script.rs')
-rw-r--r--vendor/handlebars/examples/script.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/handlebars/examples/script.rs b/vendor/handlebars/examples/script.rs
new file mode 100644
index 000000000..bedd426cd
--- /dev/null
+++ b/vendor/handlebars/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(())
+}