From 7ea9457c6f92ff4b3c4e546b6c796adf99984be6 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 11 Jun 2023 02:10:48 +0200 Subject: [PATCH] add support for + {{else}}{{#if (eq type 'select')}} + + {{else}} + + {{/if}}{{/if}} {{#if description}} {{description}} {{/if}} diff --git a/src/templates.rs b/src/templates.rs index e724fff4..0160e079 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -162,6 +162,17 @@ impl AllTemplates { handlebars_helper!(stringify: |v: Json| v.to_string()); handlebars.register_helper("stringify", Box::new(stringify)); + handlebars_helper!(parse_json: |v: Json| match v { + obj @ serde_json::value::Value::String(s) => + serde_json::from_str(s) + .unwrap_or_else(|_| { + log::warn!("Failed to parse JSON string: {}", s); + obj.clone() + }), + other => other.clone() + }); + handlebars.register_helper("parse_json", Box::new(parse_json)); + handlebars_helper!(default: |a: Json, b:Json| if a.is_null() {b} else {a}.clone()); handlebars.register_helper("default", Box::new(default));